Don't restore ViewPager when Activity is restored

萝らか妹 提交于 2020-01-02 12:46:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!