解決fragment嵌套fragment會崩潰的問題



    /**
     * 這段可以解決fragment嵌套fragment會崩潰的問題
     */
    @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);
        }
    }
發佈了48 篇原創文章 · 獲贊 3 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章