I'm implementing this application where i need to pause it when the back key is pressed or show a dialog to ask the user if he really wants to exit.
I did override the back key to show a dialog with 2 button, yes and cancel, but the activity is finished anyways without showing the dialog
the code I am using to override the back key is the following
// Overriding The Back Key To Stop The Music If Running
@Override
public void onBackPressed() {
super.onBackPressed();
show_are_you_sure_exit();
}
and the function is the following
public void show_are_you_sure_exit() {
final AlertDialog show_are_you_sure_delete = new AlertDialog.Builder(
this).create();
show_are_you_sure_delete
.setMessage("Are You Sure You Want To Exit?! Your Pregress Won't Be Saved");
show_are_you_sure_delete.setButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface StopActivityDialog,
int which) {
start_main_screen_intent();
finish();
}
});
show_are_you_sure_delete.setButton2("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
show_are_you_sure_delete.show();
}
with start_main_screen_intent() starts another activity
thx for your help :)