Why won't my AlertDialog appear when created in onResume () or onActivityResult ()?

My code is lower and works fine when called from onCreate() . I have no errors or restrictions. He just does not show.

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
   .setCancelable(false)
   .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            finish();
       }
   })
   .setNegativeButton("No", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
       }
   });
AlertDialog alert = builder.create();   
alert.show();
+5
source share
1 answer

Try it ..

    AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this);
    dlgAlert.setMessage("This is an alert with no consequence");
    dlgAlert.setTitle("App Title");
    dlgAlert.setPositiveButton("OK", null);
    dlgAlert.setCancelable(true);
    dlgAlert.create().show();

Call .show () for the builder in your code.

+2
source

All Articles