Android changing orientation issues
Where is the issue?
Developing an Android application I always had a strange error in my application and didn’t know how to prevent it. Until last week. The problem was that upon loading the application some data was loaded over the internet connection. So it sometimes took a while to load the data and the according loading dialog was shown for quite some time then. Whenever you tried to change orientation of your device (switch between landscape and portrait) the error occured:
09-11 11:12:41.601: ERROR/AndroidRuntime(264): FATAL EXCEPTION: main
java.lang.IllegalArgumentException: no dialog with id 0 was ever shown via Activity#showDialog
at android.app.Activity.missingDialog(Activity.java:2590)
at android.app.Activity.dismissDialog(Activity.java:2575)
...
at dalvik.system.NativeStart.main(Native Method)
In order to solve this error you need to prevent that your data is reloaded upon changing the screen orientation of the application. Why? Because standard when some Android configuration option changes the OS will drop the current activity and try to re-create it and so call the onCreate(Bundle savedInstance) of your activity again. If you have any loading dialog that you want to be hidden upon finishing, the application will crash because more than one loading dialog has been created and they should all be dismissed but only one will still exist.