materialsteppers icon indicating copy to clipboard operation
materialsteppers copied to clipboard

Allow using custom ViewPager and/or ViewPagerStateAdapter

Open hagabaka opened this issue 7 years ago • 0 comments

I noticed that after orientation change, my app's state does not restore correctly. I did override onSaveInstanceState in my step fragments, but it apparently gets called twice, first with the current state, and next with uninitialized values.

According to the answers on ViewPager and fragments — what's the right way to store fragment's state?, ViewPager will sometimes reuse existing fragments and sometimes create new ones. So onSaveInstanceState may be called on the old fragment which is not being displayed after orientation change. So to ensure state restoration one needs to either setOffScreenPageLimit to hold all pages, or override ViewPagerAdapter's instantiateItem to reuse fragment instances. However, since mViewPager is private to the baseStepper class, it's not possible for me to use these solutions.

hagabaka avatar May 05 '17 15:05 hagabaka