Here you can find the source of showToast(Context context, int id)
public static void showToast(Context context, int id)
//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; }// w ww . j ava 2s .c o 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(); } } }