FragmentManager NullPointerException when trying to commitAllowingStateLoss
The FragmentManager
manages all Fragments
at the Activity
level, and their lifecycle will be tied to that parent Activity
. The child Fragment
manager manages all Fragments
at the Fragment
level, and their lifecycle will be tied to that parent Fragment
.
So for your phone architecture, add your InnerFragment
to your Activity
using getFragmentManager()
. When the Activity
destroys for good (via back button / finish()
), the FragmentManager
will destroy and release the InnerFragment
for you.
For your tablet architecture, add your InnerFragments
to your Fragment
using getChildFragmentManager()
(in the latest support library). When the Fragment
destroys for good, the FragmentManager
will destroy and release the InnerFragments
for you.
You should not have to manage releasing and destroying your Fragments
yourself. I'd recommend logging the lifecycle events of your Activities
and Fragments
so you can watch them go through their states and ensure correct behavior.