I have a fragment of a support library that sends a network call, and recreate() parent action when I receive a specific network response. I see that the activity is actually recreated, as I see how onCreate() and onDestroy() called.
But after the activity is recreated, the fragment still exists, and it gets stuck in the loop, which continues to recreate and create new fragments.
Here is the onCreate() activity:
if (someLogic()) { fragmentA = new FragmentA(); FragmentUtil.addFragment(getSupportFragmentManager(), fragmentA); } else { fragmentB = new FragmentB(); FragmentUtil.addFragment(getSupportFragmentManager(), fragmentB); }
FragmentA is the one that makes the network call, and FragmentB is the fragment that should be displayed after recreate() . When I check the fragment list using getSupportFragmentManager().getFragments() , I see 1 instance of FragmentA and 16 instances of FragmentB.
My question is, why is this happening, and how to fix it?
source share