Hello, I'm hoping someone can help with this, as it's driving me absolutely nuts.
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 http://developer.android.com/guide/topics/ui/dialogs.html.
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.
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.
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.
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.
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:
OnCreate for the ProgressDialog
OnPrepare for the ProgressDialog
OnCreate for the alertDialog
OnPrepare for the alertDialog
Then, when I rotate the device (with the alertDialog still up) I see:
OnCreate for the alertDialog
OnPrepare for the alertDialog
OnCreate for the ProgressDialog
OnPrepare for the ProgressDialog
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.