I call this method to go from AFrag to BFrag:
showFragment()
{
FragmentTransaction fragmentTransaction = mFragmentMgr.beginTransaction();
fragmentTransaction.replace(R.id.operation_fragments_frame, mBFrag, mBFrag.getTag());
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
It shows a new fragment (BFrag), replaces the previous one (AFrag) and saves transaction information, so it can be automatically undo / undo on the back button.
When you click the "Back" button, everything looks fine, the previous fragment (AFrag) is displayed. But when I go ahead again (AFrag → BFrag), I got an exception "Fragment already added."
Did the reverse / undone operation delete the new fragment (BFrag)? Is this expected behavior?
This is strange because after that I decided to set a check:
if(mBFrag.isAdded())
{
fragmentTransaction.show(mBFrag);
}
else
{
fragmentTransaction.replace(R.id.operation_fragments_frame, mBFrag, mBFrag.getTag());
}
and stills, it gets into the else statement ... and I get an exception.
Any understanding of what I'm doing wrong, please?
thank.