Java tutorial
//package com.java2s; import android.os.Handler; import android.os.Looper; public class Main { private static Handler sHandler = new Handler(Looper.getMainLooper()); public static void callOnMainThread(Runnable runnable) { if (!isMainThread()) { sHandler.post(runnable); return; } runnable.run(); } public static boolean isMainThread() { return Thread.currentThread() == Looper.getMainLooper().getThread(); } }