i am new to android.i have one single activity with main.xml file. Now, i have one scroll view in that main.xml file.when i run my application in portrait mode and when i go to the bottom of the scroll view and than when i change my application state to the landscape mode than i go to the top of the scroll view..that means when we switch between portrait to landscape or vice versa the activity is recalled. so need to save the application state in portrait and restore in landscape. so any solution of it?
thanks in advance
Aamirkhan I.
i am new to android.i have one single activity with main.xml file. Now, i
Share
The documentation does a decent job of explaining different ways to handle configuration changes, including screen orientation changes. One of those methods, which is good for saving temporary state of the UI, is saving data in the
onSavedInstanceState()method–as @Jason Kuang mentioned.Generally, you can rely on Android to save and restore the state of
Views without any special effort on your part. The source code for theprotectedmethodonSaveInstanceState()explains (emphasis added):This is a little deceptive, because the API documentation states that
EditTexts andTextViews must haveandroid:freezesText="true"explicitly declared on them in your layout XML files to ensure that Android automatically stores their state whenonSaveInstanceState()is invoked. I have not tested this recently, but it is what the source code seems to be doing. Therefore, handling temporary UI state on your own is best.Another tip: You can explicitly prevent the storage of temporary data for a
Viewby callingsetSaveEnabled(false)on thatView. (This will not affect its children.)As a rule, it’s a good idea to manually save the on-screen state in your
onPause()method, and also inonSaveInstanceState().