How to clear BackStackEntries
in FragmentManager
? This is the code I use to change my fragment object:
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
Fragment homeFragment = new Home();
fragmentTransaction.replace(R.id.mainFragement, homeFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
In a particular situation I need to remove the complete backstack entries. I didn't find any particular method for that in fragment manager. Do you have any ideas?
I have been working on a method that I think does what you're asking to do, but the only thing I have been able to figure out from the documentation is whether or not this method just empties the BackStack or if there's any implication on the View container. Basically, it finds the entry located at the top of the stack and deletes everything, including that entry. If someone else thinks that there are negative implications let me know because I'd be very curious:
public static void clearBackStack(FragmentManager manager){
int rootFragment = manager.getBackStackEntryAt(0).getId();
manager.popBackStack(rootFragment, FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With