ncapdevi / FragNav

An Android library for managing multiple stacks of fragments
1.5k stars 220 forks source link

State is not peristed on rotation #177

Closed lupsyn closed 6 years ago

lupsyn commented 6 years ago

In the example app with the bottom nav with multiple stacks, in case of rotation, and in the case fragments are detached, the internal state of fragment is lost, is this the expected behaviour or I missing something? I mean :

tab 1 : [A,B,C] tab 2: [D,E]

We have custom state into A, and B we are displaying C (so A,B,D,E are detached but still present into fragment manager), we rotate (or we don't keep activities and we put the app in background) the state of A and B is lost. Is it something we can do to persist it ?

mateherber commented 6 years ago

Hi @lupsyn

For me the sample app works properly: I have the followin: Tab Nearby : [NearbyFragment 0, NearbyFragment 1, NearbyFragment 2] Tab Friends : [FriendsFragment 0, FriendsFragment 1]

After rotation and going back on Tab Nearby I still see 1 and 0 (which essentially a state of that page also if I checked the "Example to show stored state" it is shown correctly.

Since fragmenttransaction attach and detach recreates the view obviously if you have some special view state you'll have to handle it manually in your fragment (onSaveInstanceState - save, onCreateView - restore)

All above applies to 3.0.0+ version

lupsyn commented 6 years ago

@mateherber thanks for the answer, maybe i miss something, is the text into the EditText consider part of the state ? Or maybe i misunderstood what a fragment state is...

mateherber commented 6 years ago

@lupsyn In the sample nothing is persisted manually it just relies on the framework to save control's state. It seems edittext doesn't automatically persist its state to bundle however you could do that easily manually (and restore).