IllegalStateException: is not currently in the FragmentManager

后端 未结 12 2162
予麋鹿
予麋鹿 2021-01-31 08:40

I know it sounds like a duplicate of FragmentStatePagerAdapter IllegalStateException: is not currently in the FragmentManager but his solution isn\'t relevan

12条回答
  •  太阳男子
    2021-01-31 09:15

    This can happen when a FragmentStatePagerAdapter is set on a ViewPager, with the Fragments being populated, but not yet added to the FragmentManager due to the Activity pausing before layout has occurred for the ViewPager. This is reliably hit by starting another Activity from onCreate, with the Adapter also set in onCreate. In that situation, it's best to hold off on setting the Adapter, and set it onActivityResult instead. See this issue: https://code.google.com/p/android/issues/detail?id=77285

    I've also submitted a patch to check for the Fragment having been added before trying to save state.

提交回复
热议问题