Don't restore ViewPager when Activity is resto

2019-05-27 04:55发布

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?

0条回答
登录 后发表回答