Java tutorial
//package com.java2s; import android.app.Activity; import android.widget.Toast; public class Main { public static void toastOnUI(final Activity activity, final String toastText, final int duration) { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, toastText, duration).show(); } }); } }