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()) { new Handler(Looper.getMainLooper()).post(runnable); } else { runnable.run(); } } }