Fragment嵌套Fragment多次切换两次会出现Activity has been destroyed错误的解决办法

来源:互联网 发布:nero刻录软件 编辑:程序博客网 时间:2024/06/01 09:54

在嵌套子Fragment中的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);
        }
    }

0 0
原创粉丝点击