I have fragmentA on my backstack and fragmentB on the screen. I want to replace fragmentB with fragmentC so that when user pressed back, we go back to fragmentA. This is how I am replacing fragmentB with fragmentC
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.content_container, fragment);
transaction.commitAllowingStateLoss();
This is how I'm handling back press
final FragmentManager fm = getSupportFragmentManager();
if (fm.getBackStackEntryCount() != 0) {
fm.popBackStackImmediate();
} else {
super.onBackPressed();
}
After replacing fragmentB with fragmentC, when back button pressed fragmentA will be shown, but fragmentC is still visible on the screen, which is giving me some really weird UI. Anyone know why this is happening??