Here you can find the source of showToast(final Context context, String text)
public static void showToast(final Context context, String text)
//package com.java2s; import android.content.Context; import android.os.*; import android.widget.Toast; public class Main { private static Handler handler; public static void showToast(final Context context, String text) { if (null == context) { return; }/*from w ww .j av a 2s.co m*/ if (Looper.myLooper() != Looper.getMainLooper()) { if (handler == null) { handler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message msg) { String str = (String) msg.obj; Toast.makeText(context, str, Toast.LENGTH_SHORT) .show(); super.handleMessage(msg); } }; } Message message = handler.obtainMessage(); message.obj = text; message.sendToTarget(); } else { Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); } } public static void showToast(Context context, int id) { if (null != context) { Toast.makeText(context, id, Toast.LENGTH_SHORT).show(); } } }