天天看點

解決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);

        }

    }