Android : Save application state on screen orientation change

你离开我真会死。 提交于 2019-11-28 11:40:51
ingsaurabh

Well if you have the same layout for both screens then there is no need to do so just add below line in your manifest in Activity node

android:configChanges="keyboardHidden|orientation"

for Android 3.2 (API level 13) and newer:

android:configChanges="keyboardHidden|orientation|screenSize"

because the "screen size" also changes when the device switches between portrait and landscape orientation. Documentation here: http://developer.android.com/guide/topics/manifest/activity-element.html

There is another possibility using which you can keep the state as it is even on Orientation change using the onConfigurationChanged(Configuration newConfig).

Called by the system when the device configuration changes while your activity is running. Note that this will only be called if you have selected configurations you would like to handle with the configChanges attribute in your manifest. If any configuration change occurs that is not selected to be reported by that attribute, then instead of reporting it the system will stop and restart the activity (to have it launched with the new configuration).

At the time that this function has been called, your Resources object will have been updated to return resource values matching the new configuration.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!