one way is to tag backstack and if you want to clear it
mFragmentManager.popBackStack("myfancyname", FragmentManager.POP_BACK_STACK_INCLUSIVE);
where "myfancyname" should match the line you used with addToBackStack . For example.
Fragment fancyFragment = new FancyFragment(); fragmentTransaction.replace(R.id.content_container, fancyFragment, "myfragmentag"); fragmentTransaction.addToBackStack("myfancyname");
the backstack name and fragment tag name may be the same, but there are no restrictions in this regard
From the documentation
If set, and the name or identifier of the rear stack entry is specified, then all matching entries will be consumed until a match is found or the bottom of the stack is reached. Otherwise, all entries prior to but not including this entry will be deleted.
if you do not want to use the name for your backstack, you can pass the first parameter
mFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
Blackbelt Jun 14 '13 at 11:05 2013-06-14 11:05
source share