Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving a backstack across orientation change

I am trying out using fragments with my tabhost for the first time and I am pretty impressed. That said, one of my tabs uses two fragments, first the user sees Fragment A and then if they hit a button in Fragment A it gets swapped with fragment B, and puts fragment A on the backstack. This all seems to work fine, except it does something funny on a change in orientation:

If the user is on Fragment B and there is an orientation change, it still shows fragment B. However if after the orientation change, they switch to a different tab and then switch back to the original tab, it goes back to showing Fragment A.

This does not happen without the orientation change. IE... if you are just on Fragment B, switch tabs, and then switch back, you still see Fragment B. Is there any way to preserve this across an orientation change?

Thanks in advance!

like image 734
akhalsa Avatar asked Nov 13 '22 15:11

akhalsa


1 Answers

try to add this code to your manifest, for your activity:

android:configChanges="orientation|keyboardHidden"

______EDIT______

As ErstwhileIII mentioned, this is not real fix, and this will force Android to don't recreate Activity when device rotated. However, as you can see, I have answered to this question on October 14, 2011, and if you are looking for better answer, just try to find newer answers.

like image 146
Aram Avatar answered Dec 30 '22 05:12

Aram