I know that this has already been asked a lot of times but no answer could help me.
I have a dialog which will pop up at a certain moment (when I call method "showServerDialog"). The dialog is shown and everything is fine until I dismiss the dialog using a "negativeButton" and then rotate the screen. Then the dialog reappears although I dismissed it.
I read a lot of times that android handles everything automatically if I show the dialog using the showDialog(int id) method and override the onCreateDialog(int id) method. And that's exactly what I'm doing:
@SuppressWarnings("deprecation")
public void showServerDialog(int position){
showDialog(REMOVE_SERVER_DIALOG_ID);
}
@SuppressWarnings("deprecation")
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case REMOVE_SERVER_DIALOG_ID:
System.out.println("---------------------------------DIALOG");
// Create AlterDialog
Builder builder = new AlertDialog.Builder(this);
builder.setMessage("This will end the activity");
builder.setCancelable(true);
builder.setPositiveButton("I agree", new OkOnClickListener());
builder.setNegativeButton("No, no", new CancelOnClickListener());
AlertDialog dialog = builder.create();
dialog.show();
return dialog;
}
return super.onCreateDialog(id);
}
private final class CancelOnClickListener implements DialogInterface.OnClickListener{
public void onClick(DialogInterface dialog, int which) {
// Do nothing and just close dialog
}
}
But then, when I close the dialog normally using a button in the dialog and rotate the screen then it just reappears.
I'm totally stuck with it. Please help.