how I can pop specific fragment from stack and remove others from a fragment? for example these are my fragments and I'm in E right know.
A-> B -> C -> D ->E
wanna back from E to B and Clear C and D. How I can do this?
You can add a tag to each fragment while adding them to the backstack and then popfragment from backstack till the fragment with the tag you want is not reached.
FragmentManager fm = getFragmentManager();
for (int i = fm.getBackStackEntryCount() - 1; i > 0; i--) {
if (!fm.getBackStackEntryAt(i).getName().equalsIgnoreCase(tagname)) {
fm.popBackStack();
}
else
{
break;
}
}
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