Java tutorial
//package com.java2s; //License from project: Apache License import android.app.Activity; import android.util.Log; import android.widget.Toast; public class Main { private static Toast mToast; public static final void toastMessage(final Activity activity, final String message, String logLevel) { if ("w".equals(logLevel)) { Log.w("sdkDemo", message); } else if ("e".equals(logLevel)) { Log.e("sdkDemo", message); } else { Log.d("sdkDemo", message); } activity.runOnUiThread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub if (mToast != null) { mToast.cancel(); mToast = null; } mToast = Toast.makeText(activity, message, Toast.LENGTH_SHORT); mToast.show(); } }); } public static final void toastMessage(final Activity activity, final String message) { toastMessage(activity, message, null); } }