开发者

alert box is in same state when screen orientation has changed in android

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 开发者_JAVA技巧the screen orientation without causing the alert box to disappear?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜