2

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.

JustABit
  • 425
  • 4
  • 11

2 Answers2

2

So, finally I found an answer:

Instead of doing nothing in the OnClickListeners I have to call: MyActivity.this.removeDialog(REMOVE_SERVER_DIALOG_ID);

not dismiss! This works!

JustABit
  • 425
  • 4
  • 11
-2

Had the same problem ,fixed this with following line in my manifest.xml

        <activity 
        ...
        android:configChanges="orientation|screenSize|keyboardHidden"
        />

You could try this :)

Oli
  • 3,496
  • 23
  • 32
  • 1
    I really don't want to add this because I still want my app to create itself again when rotating. – JustABit Jun 01 '13 at 14:02