嵌套fragment时必须要重写 onDetach()

    /**
     * 嵌套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);
        }
    }

 

转载于:https://www.cnblogs.com/xuyunyu/p/3452939.html

你可能感兴趣的:(嵌套fragment时必须要重写 onDetach())