Hi I am using alertdialog..and when the user clicks ok it has to restart the same activty (GAME)
and when he clicks no it has to go to the main menu.. but when i click ok..2 activities
are running simultaneously and when i clock no..and come back here..the dialog is still present!
Help! This is the snippet
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setMessage("oops! wrong answer! wanna play again?");
alertbox.setPositiveButton("Yea sure!",
new DialogInterface.OnClickListener() {
Intent game = new Intent("nik.trivia.GAME");
startActivity(game);
finish();
});
alertbox.setNegativeButton("Nope! take me to the main menu",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent menu = new Intent("nik.trivia.MENU");
startActivity(menu);
finish();
}
});
You need to call
dismiss()on yourAlertDialogafter the user has clicked a button.EDIT: just place this line of code:
inside the
onClickmethod.