Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.*; import android.content.DialogInterface; import android.util.Log; public class Main { public static void failExit(final Activity activity, final String task, final String msg, final Object o) { if (o instanceof Exception) { Exception e = (Exception) o; String emsg = e.getClass().getName() + ": " + e.getMessage(); String m = task + " " + msg + ": " + emsg; Log.e(task, m); alert(activity, m, "ok", true); } else { alert(activity, "Hop Fail Exit: " + o.toString(), "ok", true); } } public static void alert(final Activity activity, final String msg, final String ok, final boolean exit) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setMessage(msg).setCancelable(false).setPositiveButton(ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); if (exit) { activity.setResult(activity.RESULT_CANCELED); activity.finish(); } } }); AlertDialog alert = builder.create(); alert.show(); } public static void alert(final Activity activity, final String msg) { alert(activity, msg, "ok", false); } }