I have 3 fragments, and I'm navigating using bottom menu (3 items), lets say I navigate this way :
A -> B -> C -> B -> C
when I press the back button, that's what will happen
A <- B <- C <- B <- C
and what I want is this
A <- B <- C
that's mean if add fragment that's already added the old one must be deleted, more precisely remove the transaction from the back stack
this code will not work because we are adding new transaction here :
FragmentTransaction transaction = mContext.beginTransaction();
Fragment lastFragment = mContext.findFragmentByTag(mFragmentTag);
if (lastFragment != null) {
transaction.remove(lastFragment);
transaction.commit();
}
btw, may some developers make a mistake, but the back stack stores transactions and NOT fragments.