I was facing the same issue in my app.
Stack Trace:
java.lang.IllegalStateException: Fragment has not been attached yet. android.support.v4.app.Fragment.instantiateChildFragmentManager(Fragment.java:2154)
android.support.v4.app.Fragment.getChildFragmentManager(Fragment.java:704)
The app was crashing at this line:
function performSomeActionInChildFragments() {
List<Fragment> fragments = getChildFragmentManager().getFragments();
...
}
This happens when the fragment is no longer attached to its parent activity/fragment. So a simple isAdded()
check should resolve this issue for you.
Fix:
function performSomeActionInChildFragments() {
if (!isAdded()) return;
List<Fragment> fragments = getChildFragmentManager().getFragments();
...
}
From documentation:
isAdded() - Return true if the fragment is currently added to its activity.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…