one way is to tag the backstack and when you want to clear it
mFragmentManager.popBackStack("myfancyname", FragmentManager.POP_BACK_STACK_INCLUSIVE);
where the "myfancyname" should match the string you used with addToBackStack. E.g.
Fragment fancyFragment = new FancyFragment();
fragmentTransaction.replace(R.id.content_container, fancyFragment, "myfragmentag");
fragmentTransaction.addToBackStack("myfancyname");
the backstack's name and the fragment's tag name can be the same but there are no constrains on this regard
From the documentation
If set, and the name or ID of a back stack entry has been supplied,
then all matching entries will be consumed until one that doesn't
match is found or the bottom of the stack is reached. Otherwise, all
entries up to but not including that entry will be removed.
if you don't want to use a name for your backstack you can pass use a first parameter
mFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);