The right way to do this is to use the onBackPressed() method to catch this event in your application, and then pop the backStack using popBackStack() . For instance:
public void onBackPressed() { // Catch back action and pops from backstack // (if you called previously to addToBackStack() in your transaction) if (getSupportFragmentManager().getBackStackEntryCount() > 0){ getSupportFragmentManager().popBackStack(); } // Default action on back pressed else super.onBackPressed(); }
PD: Sorry for the delay in answering, but I just saw your question. Hope this helps!
source share