Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.os.Handler; import android.os.Looper; import android.widget.Toast; public class Main { public static void showToast(final Context c, final CharSequence text) { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (c == null) return; Toast.makeText(c, text, Toast.LENGTH_SHORT).show(); } }); } public static void showToast(final Context c, int resId) { String text = c.getString(resId); showToast(c, text); } }