Friday, September 16, 2011

How to Set a AlertDialog before closing the App


@Override
public void onBackPressed() {
   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) {
                   FirstScreenActivity.this.finish();
              }
          })
          .setNegativeButton("No", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                   dialog.cancel();
              }
          });
   AlertDialog alert = builder.create();
   alert.show();


}

No comments:

Post a Comment