getting exception “IllegalStateException: Can not perform this action after onSaveInstanceState”

前端 未结 30 2651
迷失自我
迷失自我 2020-11-22 05:12

I have a Live Android application, and from market i have received following stack trace and i have no idea why its happening as its not happening in application code but it

30条回答
  •  不知归路
    2020-11-22 05:55

    Well, after trying all the above solutions without success (because basically i dont have transactions).

    On my case i was using AlertDialogs and ProgressDialog as fragments that, sometimes, on rotation, when asking for the FragmentManager, the error rises.

    I found a workaround mixing some many similar posts:

    Its a 3 step solution, all done on your FragmentActivity (in this case, its called GenericActivity):

    private static WeakReference activity = null; //To avoid bug for fragments: Step 1 of 3
    
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        //To avoid bug for fragments: Step 2 of 3
        activity = new WeakReference(this);
    }
    
    @Override
    public FragmentManager getSupportFragmentManager(){
        //To avoid bug for fragments: Step 3 of 3
        if (this == activity.get()) {
            return super.getSupportFragmentManager();
        }
        return activity.get().getSupportFragmentManager();
    }
    

提交回复
热议问题