I have a program. The first activity is a splash screen and the second is the log in and the third is a list view menu activity, and then 2 other activities.
The splash screen disappear after 3 seconds and if the log in check box remember me is checked, it goes directly to the menu page.
I override the onBackPressed function in the menu activity so that it will exit the program directly after the user click back from the menu. However, if I have gone through the other activities it doesn't exit; it goes to the previous activity in the stack and the dialog box doesn't pop up, although it actually does appear for a second no less and disappear right away.
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();
}