I have an Activity that throws an AlertDialog under certain circumstances.
However, if you rotate the device, the activity will be destroyed and recreated, and AlertDialog will disappear.
How do people deal with this?
It would be easy to save some flag in savedInstanceState, letting the activity know to throw the AlertDialog again after creation, but what if your AlertDialog needs a lot of data and this data is dynamic? It will be very ugly.
Especially in my case:
When my application wants to make a call to a web service, it downloads the IntentService, passes the Intent with the necessary data (credentials and data to send to the web service) and starts. If the Intent handled by the IntentService fails due to a login error, it sends a message that my actions will hear. I expanded the Activity and ListActivity and added BroadcastReceiver to them. My application works from them. Then they pop up to AlertDialog, asking for user credentials. Intent's original add-ons are also transferred together, so after a successful login, it can be re-processed. Unfortunately, when the user changes the screen orientation (for example, pulling out the hardware keyboard), AlertDialog will disappear.
source
share