Reputation: 301
My Android app shows an alert box. If the user doesn't select a button in the alert box, I change the screen orientation which causes the alert box to disappear. How can I change the screen orientation without causing the alert box to disappear?
Upvotes: 0
Views: 474
Reputation: 189464
Just add
android:configChanges="keyboardHidden|orientation"
to the activity tag of every activity that you don't want to restart on a change from landscape to portrait mode in your manifest.xml. This will cause the OS to rebuild your layout without destroying it before the rebuild. The oncreate method will not get called again and you don't loose the state of the activity. But be carefull this will only work if you use the same layout file for portrait and landscape mode.
See this question for more information on this topic
Upvotes: 1
Reputation: 3481
When you change orientation, your activity is destroyed and onCreate is called again.
Override onConfigurationChanged if you don't want this behavior - or even override this behavior by defining android:configChanges in your manifest-file.
Alternatively, save your dialog state on onSaveInstanceState and restore it on onRestoreInstanceState
Upvotes: 1