Expected the adapter to be 'fresh' while restoring state

前端 未结 7 2462
一个人的身影
一个人的身影 2021-02-20 10:24

I have a viewpager2 with multiple fragments in FragmentStateAdapter. Whenever I try to open a new fragment and then go back to my current one with viewpager2, I get an exception

7条回答
  •  北海茫月
    2021-02-20 11:02

    I was also getting this java.lang.IllegalStateException: Expected the adapter to be 'fresh' while restoring state. when using ViewPager2 within a Fragment.

    It seems the problem was because I was executing mViewPager2.setAdapter(mFragmentStateAdapter); in my onCreateView() method.

    I fixed it by moving mViewPager2.setAdapter(mMyFragmentStateAdapter); to my onResume() method.

提交回复
热议问题