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 sHandler; public static <T> T callInMainThread(Callable<T> call) throws ExecutionException, InterruptedException { FutureTask<T> task = new FutureTask<T>(call); sHandler.post(task); return task.get(); } }