Expected the adapter to be 'fresh' while restoring state

前端 未结 7 2484
一个人的身影
一个人的身影 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 10:44

    So my problem was that I was creating my FragmentStateAdapter inside my Fragment class field where it was only created once. So when my onCreateView got called a second time I got this issue. If I recreate adapter on every onCreateView call, it seems to work.

提交回复
热议问题