问题
The setup of my project is as follows
Activity
has Fragment
and it has ViewPager
with pages supplied by FragmentStatePagerAdapter
.
The data displayed by ViewPager
is fetched from network.
When Activity
is destroyed and restored, it tries to restore the Fragment
that was visible in ViewPager
when the Activity
was destroyed. But the Fragment
inside the ViewPager
tries to access data structures that are not fully initialized, as a result crash happens.
I don't want the Fragment
in ViewPager
to be recreated
.
One way that works is to pass null
in super.Oncreate(savedInstance)
of the Activity
. But it will not allows me to restore state in any of other Fragments
also which is not what I want.
What is the correct way to do it?
来源:https://stackoverflow.com/questions/38727802/dont-restore-viewpager-when-activity-is-restored