I am working on fragment transaction, and the backstack is like this:
fragA => fragB => fragC => fragD
I would like to return to f
You an override the onbackpressed (Mainactivity) and using the getBackStackEntryCount() of the fragment manager, you can check if its not equal to 1 and popbackstack on only that condition.
@Override
public void onBackPressed() {
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
if (!(getSupportFragmentManager().getBackStackEntryCount() == 1)) {
getSupportFragmentManager().popBackStack() ;
}
}
}