Update: After some exhaustive testing in a wide variety of different scenarios I have come to realise this approach doesn't work in all situations and I am yet to find an elegant solution to handle progress dialogs across orientation change events!
There's a bug with Android managed dialogs (pop-ups) that has been annoying me for days. Imagine an application where you need to drill down to some specific content via a list and detail screen. You click an item on the list screen to start a long running connection to the server and the ProgressDialog is initiated, the user then changes the screen orientation between landscape and portrait (with the task running and the dialog showing), the connection finally finishes and the new detail screen (Activity) is started. On the detail screen the user changes orientation again and clicks back. In every instance using managed dialogs the connection pop-up is still running on the list screen even if you have tried to dismiss it before redirecting. I'm a stickler for perfect usability so this has been driving me mad.
My solution was to stop using managed dialogs altogether. Instead I created the following 4 methods to replace the default Android way of doing things. Notice the static boolean called isMyDialogShowing, this boolean persists across the entire life cycle of your Activity and is used to determine whether or not to show the dialog.
不让屏幕翻转扰乱你的进度对话框_职场
The second part of the puzzle is how to use these methods and the boolean in order to have perfect control of your dialogs across both Activity and orientation changes. In the onCreate() method the first thing I do is call setUpMyDialog(). If the ProgressDialog is null the method instantiates it. The second thing I do is check the static isMyDialogShowing boolean to see if my connection dialog should be showing. If the boolean is false I don't call the showMyDialog() method.
If the page has just been loaded for the first time the dialog won't be showing so you will need a user initiated event to start the dialog. In this example I have used a simple button click. When the button is pressed I call my showMyDialog() method for the first time and this displays the previously instantiated dialog and sets the isMyDialogShowing static boolean to true. Every time the page is changed via orientation change or redirection I dismiss the dialog via the onPause() method. Basically that means the dialog is being both shown and dismissed every time the page changes due to an orientation switch.
不让屏幕翻转扰乱你的进度对话框_android 屏幕翻转 进度对话框_02
The final ingredient is to call the killMyDialog() method when your connection has finished and you are about to start a new Activity. This sets the isMyDialogShowing boolean to false and ensures that the dialog is never showing when you return to the Activity at a later date.
不让屏幕翻转扰乱你的进度对话框_android 屏幕翻转 进度对话框_03

原文引至:http://www.paxmodept.com/telesto/blogitem.htm?id=766