I have a weird bug in my program which I can only explain in one way.
When I click on a certain button in my menu screen the user gets an AlertDialog which asks him how he wishes to proceed.
Whichever he chooses he is then passed on to another activity.
Thing is, than when the user exits that activity and thus returns to the menu activity, the dialog seems to be still open.
Thing is that it doesn’t happen every time.
I haven’t put a dismiss() in my code but I was sure that it does so automatically.
AlertDialog alertDialog = new AlertDialog.Builder(YanivMenuActivity.this).create();
alertDialog.setTitle("Active Game");
alertDialog.setMessage("You are in the middle of a game.\nStarting a new game will cancel that one.\nHow do you wish continue?");
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Start New Game",
new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface arg0, int arg1) {
inGame = false;
startActivity(new Intent(YanivMenuActivity.this,YanivGameActivity.class).putExtra("reset", true));
}
});
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Continue Old Game",
new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface arg0, int arg1) {
startActivity(new Intent(YanivMenuActivity.this,YanivGameActivity.class).putExtra("reset", false));
}
});
alertDialog.show();
You’ve almost answered your own question. You need to call
dismiss()just before yourstartActivity(...);call.