Java tutorial
//package com.java2s; import android.os.Handler; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; public class Main { private static Handler handler; public static <T> T callInMainThread(Callable<T> call) throws ExecutionException, InterruptedException { FutureTask<T> task = new FutureTask<T>(call); handler.post(task); return task.get(); } }