On Mon, Nov 1, 2010 at 3:04 PM, Prasanna Perera <[email protected]>wrote:
> The problem is when I try to rotate again to portrait. I get > 'java.lang.IllegalArgumentException: no dialog with id 1 was ever shown > ...'. id 1 is for the REFRESH_DIALOG. > I ran into this. The problem is you have the AsyncTask running off by itself and it doesn't realize it's owning activity has been killed. Sequence is like this: Activity 1 -> Show Dialog 1 -> Run Asynctask 1 -> Rotate Activit 2 (remember, Android kills your original Activity and starts over) -> Now, before you show the dialog again, Asynctask 1 finally completes and calls dismissDialog on Activity 2, where the dialog has not been shown yet. -> Boom > How do I get rid of this error? > Keep a reference to your AsyncTask, call cancel() on it in onDestroy(), dismiss the dialog immediately in onCancelled(), and do nothing in onPostExecute if the task isCanceled(). That's one idea. There are more involved, fancier ways to keep your original Asynctask around across the rotation so you don't have to do all this but that's arguably more complicated. ------------------------------------------------------------------------------------------------- TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

