Popbackstack is working fine when all the fragments in the sequence are added in the backstack but isnt working when one of the transactions is not added in the backstack.
Here is my navigation:
1.Replace fragment to load home fragment. This transaction not added to backstack.
Replace fragment to load login fragment. This transaction is added to backstack.
3.Replace fragment to load loggedin fragment. This transaction is not added to backstack.
Now, when i press back button once nothing happens. Whereas ideally it should go to the home fragment from logged in fragment. Here is my onbackpressed method in main activity:
@Override public void onBackPressed() { if(getSupportFragmentManager().getBackStackEntryCount()>0) { FragmentManager.BackStackEntry backStackEntry = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1); String str = backStackEntry.getName(); FragmentManager fm=getSupportFragmentManager(); //getSupportFragmentManager().popBackStackImmediate(); fm.popBackStack(str, FragmentManager.POP_BACK_STACK_INCLUSIVE); } else { super.onBackPressed(); } }