Java tutorial
//package com.java2s; import android.app.Activity; import android.widget.Toast; public class Main { public static void safeToastMessageShow(Activity pActivity, String pToastMsg, int pToastLength) { final String toastMsg = pToastMsg; final int toastLength = pToastLength; final Activity activity = pActivity; activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity.getApplicationContext(), toastMsg, toastLength).show(); } }); } }