zoukankan      html  css  js  c++  java
  • Java.lang.IllegalStateException Activity has been destroyed

    03-04 12:01:05.468: E/AndroidRuntime(2474): FATAL EXCEPTION: main
    java.lang.IllegalStateException: Activity has been destroyed 
        at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1345) 
        at android.app.BackStackRecord.commitInternal(BackStackRecord.java:597) 
        at android.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:579) 
        at android.support.v13.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143) 
        at android.support.v4.view.ViewPager.dataSetChanged(ViewPager.java:892) 

    bug出现的原理问题及解决方法是
    This seems to be a bug in the newly added support for nested fragments. Basically, the child FragmentManager ends up with a broken internal state when it is detached from the activity. A short-term workaround that fixed it for me is to add the following to onDetach() of every Fragment which you call getChildFragmentManager() on:

    解决方法重写onDetach()

    @Override
    public void onDetach() {
        super.onDetach();

        try {
            Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
            childFragmentManager.setAccessible(true);
            childFragmentManager.set(this, null);

        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    问题解决方法是参考文章:http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed

  • 相关阅读:
    UOJ168. 【UR #11】元旦老人与丛林
    luogu3308,LOJ 2196 [SDOI2014]LIS
    CF1349F2. Slime and Sequences (Hard Version)
    6210. wsm
    欧拉数学习小记
    CF1508F. Optimal Encoding
    CF1508C. Complete the MST
    联合省选2021 游记
    一. Docker介绍
    Elasticsearch
  • 原文地址:https://www.cnblogs.com/xueqiang911226/p/3793427.html
Copyright © 2011-2022 走看看