Java tutorial
//package com.java2s; import android.app.Activity; import android.widget.Toast; public class Main { public static void show(final Activity activity, final String text) { if ("main".equalsIgnoreCase(Thread.currentThread().getName())) { Toast.makeText(activity, text, Toast.LENGTH_SHORT).show(); } else { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, text, Toast.LENGTH_SHORT).show(); } }); } } }