Note that there are some explanatory texts on larger screens.

plurals
  1. POshowDialog rotation issue when two dialogs are used
    text
    copied!<p>I'm hoping someone can help with this, as it's driving me absolutely nuts.</p> <p>I have a ProgressDialog, which tells the user my app is connecting to a server. It's launched using "showDialog(CHECKING_USER_NAME_AND_PASSWORD_AVAILABILITY);" so that the activity will manage its state for me (specifically, I want the ProgressDialog to stay visible if the device is rotated and I don't want to manage the state myself). Therefore, I am using onCreateDialog, as described here <a href="http://developer.android.com/guide/topics/ui/dialogs.html" rel="nofollow noreferrer">http://developer.android.com/guide/topics/ui/dialogs.html</a>.</p> <p>When the server responds, my app displays an AlertDialog by calling "showDialog(USER_NAME_AND_PASSWORD_NOT_AVAILABLE); When OK is clicked "dismissDialog(CHECKING_USER_NAME_AND_PASSWORD_AVAILABILITY);" is called to remove the ProgressDialog.</p> <p>First I'll describe a normal working scenario. User clicks button, ProgressDialog appears, AlertDialog appears (note that I can still see a little bit of the ProgressDialog behind it, as expected), user clicks OK and both Dialogs disappear.</p> <p>And here's a non-working scenario: User clicks button, ProgressDialog appears, AlertDialog appears, user rotates the device. NOW THIS IS WHERE IT GOES BAD - now the AlertDialog is behind the ProgressDialog and the ProgressDialog is in front. There's no way to close the ProgressDialog since it closes when the user clicks OK in the alertDialog.</p> <p>I've tried moving the dismissDialog for the ProgressDialog to various places in the code (like when immedidately when the server responds), but everything I try seems to have different issues.</p> <p>I stuck some toast messages in the app, and it appears the calling order of the onCreateDialog and onPrepareDialog methods gets reversed, which explains the problem. For example, when I first launch the app I see this calling order:<br></p> <p>OnCreate for the ProgressDialog<br> OnPrepare for the ProgressDialog<br> OnCreate for the alertDialog<br> OnPrepare for the alertDialog<br></p> <p>Then, when I rotate the device (with the alertDialog still up) I see:<br> OnCreate for the alertDialog<br> OnPrepare for the alertDialog<br> OnCreate for the ProgressDialog<br> OnPrepare for the ProgressDialog<br></p> <p>Does anyone have any suggestions? I'm starting to feel like I need to use onSaveInstanceState, which sort of defeats the point of using showDialog in the first place.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload