Reputation: 4427
How can I save the state of my tabs when the device Orientation
is changed?
I have an ArrayList
that holds all the currently open tabs
ArrayList<TabHost.TabSpec> mTabList = new ArrayList<TabHost.TabSpec>();
Changing the Orientation
of the device clears all the tabs the user created.
I would do it with savedInstanceState
but I don't know how to bundle it, if that's even possible.
What are your suggestions?
Upvotes: 0
Views: 2316
Reputation: 7098
If your requirement is to save the state of the application on orientation without stopping the default behaviour on orientation changed,refer this Reference
you can use savedInstanceState.putParcelableArrayList(key, value)..The whole idea would depend on whether you want to load the resoures again on orientation change say if your using different layout resources for landscape and portrait modes .otherwise handling using android:configChanges="orientation" would be better choice
Upvotes: 0
Reputation: 1307
Hey Buddy just put in the manifest file
<activity android:name="YourActivityName" android:configChanges="orientation|keyboardHidden"></activity>
Just keep in mind
android:configChanges="orientation|keyboardHidden"
if the above solution isn't work for you in your case then you can use
Saving Android Activity state using Save Instance State
Hope this will work...
Upvotes: 1
Reputation: 24857
In the manifest for your activity that contains the list in question add configChanges attribute to it. For the value of the attribute set it to "orientation". This should stop the default behavior of restarting the activity which is why your list is getting cleared.
Upvotes: 1