java.lang.IllegalStateException: Activity has been destroyed

前端 未结 1 1487
情话喂你
情话喂你 2021-01-07 06:55

I know that there are several similar questions.

@Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInsta         


        
相关标签:
1条回答
  • 2021-01-07 07:26

    This is know issue look here

    This is a bug in the nested fragments. Basically, the child FragmentManager ends up with a broken internal state when it is detached from the activity.

    A short-term workaround is to add the following code in your 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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题