pop a fragment from backstack from fragment code example
Example 1: Pop fragment from backstack
getActivity().getSupportFragmentManager().popBackStack();
Example 2: Pop fragment from backstack
FragmentManager fm = getSupportFragmentManager();
if (fm.getBackStackEntryCount() > 0) {
fm.popBackStack();
}else {
super.onBackPressed();
}