Java tutorial
//package com.java2s; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Handler; public class Main { public static void displayAlert2Handler(final Context context, final String title, final String message, final String buttonText, Handler handler) { handler.post(new Runnable() { @Override public void run() { displayAlert(context, title, message, buttonText); } }); } public static void displayAlert(Context context, String title, String message, String buttonText) { AlertDialog alertDialog = new AlertDialog.Builder(context) .setPositiveButton(buttonText, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).setTitle(title).setMessage(message).create(); alertDialog.show(); } }