0

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?

Vivek Kalkur
  • 2,200
  • 2
  • 21
  • 40
bwoogie
  • 4,339
  • 12
  • 39
  • 72

3 Answers3

1

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.

Bobbake4
  • 24,509
  • 9
  • 59
  • 94
  • ok... I added that, its calling onConfigurationChanged but its still calling onCreate also... o_O so the tabs are still getting reset... – bwoogie Nov 23 '11 at 03:38
  • being that it extends TabActivity wouldnt affect it... would it? -edit- it also isnt calling onConfigurationChanged when switching to landscape mode - only portrait. I must be doing something wrong.... – bwoogie Nov 23 '11 at 03:55
  • 1
    Hmm I'm getting this each time I change orientation... 11-22 22:00:55.503: W/PhoneWindow(1051): Previously focused view reported id 2131230728 during save, but can't be found during restore. – bwoogie Nov 23 '11 at 04:02
1

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...

Community
  • 1
  • 1
Last Warrior
  • 1,307
  • 1
  • 11
  • 20
0

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

Community
  • 1
  • 1
MGK
  • 7,050
  • 6
  • 34
  • 41