How do I retain the state of an activity in android? I have two layouts for portrait and landscape in layout and layout-land. I am loading the value from service at the time I am showing progress dialog. If loaded user rotates the device to landscape at the time also loading. How do I avoid that? user typed content in webview that also refreshed. How do I avoid that, can anybody provide an example?
Thanks
You can use the
onRetainNonConfigurationChange()callback to store arbitrary data. It is called just before your application is about to be recreated.Then, in
onCreate()just check if some data were put aside by callinggetLastNonConfigurationInstance()that returns the Object you put aside or null.See this article on android developers.
Here’s a sample borrowed from the link above:
Automagic restore of previously saved state: