Local variable not restored on orientation change for fragments in backstack

119 Views Asked by At

I have two fragments, FragmentA and FragmentB, the user can go from FragmentA to FragmentB

Let's say FragmentA has a local variable varA. When the user is on FragmentA and changes orientation I can save that variable with onSaveInstanceState and then restore it in onViewCreated. No problem there.

However, when the user is on FragmentB and the orientation changes, onSaveInstanceState is called for FragmentA, but onViewCreated is never called and the variable is never restored.

How can I restore the variable properly?

0

There are 0 best solutions below