ncapdevi / FragNav

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

the previous fragment is recreated when i pop the current fragment. #94

Closed anuragdalia closed 6 years ago

anuragdalia commented 6 years ago

So i just implemented your fragnav library it seems to work the way it should with just one issue the fragment thats immediately before the current fragment seems to be recreated when i pop the current fragment. Is this how its intended to work? I can add code samples if you want.

jishhd commented 6 years ago

I'm experiencing this same issue with 2.4.0, except only with root fragments. Keeps recreating the view (calling onCreateView in the fragment) even when the fragment itself is not null (I can see variables still persisted from the last time I had the fragment in focus).

Any solutions?

vjyanand commented 6 years ago

I'm experiencing this same issue with 2.4.0

ncapdevi commented 6 years ago

This is intentional Android behavior. https://developer.android.com/guide/components/fragments.html#Lifecycle http://daniel-codes.blogspot.com/2012/06/fragment-transactions-reference.html https://inthecheesefactory.com/blog/fragment-state-saving-best-practices/en

The sample app in the repo has been updated with a checkbox and an edit text field, you can see that if you modify those, and return to the fragment either via switching back to it from a tab, or by pushing a fragment on top of it, and then returning, the state is correctly restored. Any other state that you need to restore is well outside the scope of this library, I can suggest https://github.com/frankiesardo/icepick