How to delete all fragments?

I tried this:

for (Fragment fragment: fragmentmanager.getFragments()) { fragmentmanager.beginTransaction().remove(fragment).commit(); } 

Tried it like this:

 FragmentManager fm = getActivity().getSupportFragmentManager(); for(int i = 0; i < fm.getBackStackEntryCount(); ++i) { fm.popBackStack(); } 

In the second variant, nothing happens at all.

In the first variant, they are actually deleted from the activation, but checking for their presence returns that they are:

 if (fragmentmanager.findFragmentByTag(TAG) == null) { } 

And if you just check fragmentmanager.getFragments () after deletion, it will be full of fragments.

I want to delete the history of all fragments from the activation and load only one fragment.

Simply replace cannot be used, it will be a conflict that this fragment is already loaded.

  • Faced a similar problem. The question was asked long ago - was it possible to find a solution? - Noname Noferstname

0