Java tutorial
//package com.java2s; import android.os.Handler; import android.os.Looper; public class Main { public static void runOnUiThread(final Runnable runnable) { if (Looper.myLooper() == Looper.getMainLooper()) { runnable.run(); } else { new Handler(Looper.getMainLooper()).post(runnable); } } }