'IllegalStateException: Activity has been destroyed' when 'getSupportFragmentManager()' called after Activity restart

后端 未结 5 1343
猫巷女王i
猫巷女王i 2020-12-30 11:57

I have a parent Fragment Activity that has a ViewPager which contains a child ViewPager. The child ViewPager contains Fragments for each page. I communicate between these ch

5条回答
  •  梦谈多话
    2020-12-30 12:33

    Had a similar issue. Basically if the ViewPager just has couple of fragments, then store references to them in current activity. DO NOT call pagerAdapter's getItem() because it creates a new fragment and it is not attached to any activity and that's why we see "Activity has been destroyed" exception. If you don't want to keep fragment references, then you can use findViewWithTag() method to get Fragment object.

提交回复
热议问题