Closed sauyee333 closed 6 years ago
This is normal. On the backstack the fragment is paused, and then resumed when it is restored. The view is not destroyed in this case so state does not need to be restored.
If the device is rotated while the fragment is on the backstack then the view is destroyed and state is saved as expected.
This is just normal android fragment saved state behavior and not related to Epoxy.
But the scroll position will get reset when resume from stack?
No, that's now how the fragment lifecycle works. If the view is not destroyed then nothing with its state should change unless you are manually doing some modification in one of the lifecycle callbacks (onResume, onPause, etc).
If you set up the recyclerview and epoxy controller in fragment#onActivityCreated (and then never touch it again) it should restore fine off the backstack with no extra configuration.
Thanks for the info. But calling in fragment#onActivityCreate or fragment#onCreateView the same. The position in carousel (horizontal recyclerview) still get reset whenever coming back to fragment. Vertical recyclerview is ok. I'll try overwrite carousel and store position. Thanks.
@sauyee333 oh, you're talking about a nested recyclerview? that's very different...
You have to enable saved state for the model https://github.com/airbnb/epoxy/wiki/Saving-View-State
Thanks for the info. Found the issue: we used replace fragment instead of add fragment. After changing to transaction.add fragment, the position remains.
When using fragment, only onPaused is called instead of onSaveInstanceState. How can states like scroll position restored when back to the fragment? Thanks.