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

后端 未结 5 1317
猫巷女王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:38

    I had a similar issue, I think it is because the fragments are retained and are keeping a reference to a destoryed activity, my solution was to keep a reference to the fragment in the activity e.g Fragment myfragment = null. And then use the following code in MyFragment:

        public void onAttach(Activity activity) {
            super.onAttach(activity);
            ((TestActivity)activity).contentFragment = this;
    }
    

提交回复
热议问题