materialsteppers
materialsteppers copied to clipboard
Allow using custom ViewPager and/or ViewPagerStateAdapter
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.