Fatal Exception: java.lang.IllegalStateException: Failure saving state: active fragment was removed from the FragmentManager

Which Fragment library version did you use? There is an issue with 1.1.0-alpha01.


I am using the latest gradle as below

implementation 'androidx.core:core:1.1.0-alpha03'

I have compared crashing fragment with other fragment code and found the difference as below: Crashing fragment has method setRetainInstance(true); inside onCreateView() as shown in below snippet.

     @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       setRetainInstance(true);
}

I come across the link which says not to use setRetainInstance : setRetainInstance - This can only be used with fragments not in the back stack

I removed the setRetainInstance(true) for crashing fragmnet; It's working now.

How to replicate this issue: MainActivity --> HomeFragment --> FirstFragment(crashing fragment) --> HomeFragment

MainActivity loads with HomeFragment which replaced by FirstFragment and then going back to HomeFragment. Then moving my app to background and crash happens with below exception.

 java.lang.IllegalStateException: Failure saving state: active 
FirstFragment{fd50037 (4a8b618e-a0a8-45d0-aa37-ba08393b8f68)
 id=0x7f08009c} was removed from the FragmentManager