Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.os.Handler; import android.os.Looper; import android.widget.Toast; public class Main { private static Handler handler = new Handler(Looper.getMainLooper()); public static void makeToast(final Context context, final String text) { runInUIThread(new Runnable() { @Override public void run() { Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); } }); } public static void runInUIThread(Runnable runnable) { runInUIThread(runnable, 0); } public static void runInUIThread(Runnable runnable, long delayMillis) { handler.postDelayed(runnable, delayMillis); } }