I have a program. The first action is the splash screen, and the second is the login, and the third is the presentation of the list menu, and then 2 other actions. The splash screen disappears after 3 seconds, and if the โRemember meโ checkbox is checked by me, it appears directly on the menu page.
I redefine the onBackPressed function in the menu action so that it onBackPressed program immediately after the user clicks it on the menu. However, if I experienced other activities, he did not go out; it moves to the previous action on the stack, and the dialog box does not appear, although it does appear for a second no less and immediately disappears.
Here is my onBackPressed function
public void onBackPressed() { // super.onBackPressed(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you Sure want to close the Application..?") .setCancelable(false) .setTitle("EXIT") .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }); AlertDialog alert = builder.create(); alert.show(); //super.onBackPressed(); }
source share