show Error Dialog And Finish - Android android.app

Android examples for android.app:AlertDialog

Description

show Error Dialog And Finish

Demo Code

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.TypedValue;

public class Main {

  public static void showErrorAndFinish(final Activity activity, int msgId) {
    DialogInterface.OnClickListener buttonListener = new DialogInterface.OnClickListener() {
      @Override//ww  w . j ava 2  s .  c o  m
      public void onClick(DialogInterface dialog, int which) {
        activity.finish();
      }
    };
    TypedValue out = new TypedValue();
    activity.getTheme().resolveAttribute(android.R.attr.alertDialogIcon, out, true);
    new AlertDialog.Builder(activity).setCancelable(false).setTitle("title").setMessage(msgId)
        .setNeutralButton("OK", buttonListener).setIcon(out.resourceId).show();
  }

}

Related Tutorials