Android - dismissDialog does not dismiss the dialog
<p>I am using the <code>showDialog()</code> and <code>dismissDialog()</code> to show progress dialogs in my app. Moved from creating the dialog and calling <code>show()</code> on it to using this in order to save state when changing orientation.</p>

<p>But when I change the orientation from portrait->landscape->portrait, the <code>dismissDialog()</code> no longer dismisses the dialog. The dialog stay there all the time and I need to press the back button for it to disappear.</p>

<p>Any reason why it would behave that way?</p>

<p><strong>Edit</strong></p>

<p>To overcome this issue, I tried adding a <code>removeDialog()</code> in <code>onDestroy()</code> so that the dialog is not created/displayed twice and before orientation change, the dialog is removed. Tried adding log statements and see what happens</p>

<pre><code>05-21 12:35:14.064: DEBUG/MyClass(193): *************callingShowDialog
05-21 12:35:14.064: DEBUG/MyClass(193): *************onCreareDialog

05-21 12:35:15.385: DEBUG/MyClass(193): *************onSaveInstanceState
05-21 12:35:15.415: DEBUG/MyClass(193): *************onDestroy

05-21 12:35:15.585: DEBUG/MyClass(193): *************callingShowDialog
05-21 12:35:15.585: DEBUG/MyClass(193): *************onCreareDialog
05-21 12:35:15.715: DEBUG/MyClass(193): *************onCreareDialog
05-21 12:35:17.214: DEBUG/MyClass(193): *************onSaveInstanceState
05-21 12:35:17.214: DEBUG/MyClass(193): *************onDestroy

05-21 12:35:17.275: ERROR/WindowManager(193): android.view.WindowLeaked: Activity com.android.MyClass has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43362088 that was originally added here

05-21 12:35:17.395: DEBUG/MyClass(193): *************callingShowDialog
05-21 12:35:17.395: DEBUG/MyClass(193): *************onCreareDialog
05-21 12:35:17.475: DEBUG/MyClass(193): *************onCreareDialog
</code></pre>

<p>If we see here, initially when the activity is displayed, the onCreateDialog is called once and on changing the orientation, onSaveInstanceState and onDestroy are called.</p>

<p>But after that, onCreateDialog is called twice (once by a call to showDialog which I make, but why the 2nd time?) and this happens every time I change the orientation hence forth.</p>

<p>Any idea why that happens?</p>

<p>Thanks again</p>
