The correct behavior I'd like to have is:
Fragment A -> Fragment B -> Fragment C -> Fragment A
What I currently do:
- When I want to go back from B to A, I use
popBackStack()
still here everything goes well. - When I want to go from B to C I remove B and add C. (number of Fragments 2, number of backStackEntryCount 3, same for replace).
- When I want to go back from C to A, I can use
popBackStack()
but the BackStackEntryCount will still contain the entry for B.
I really need the backStackEntryCount
to be the same as the fragments contained in the manager.
Anyone know what I am doing wrong?
My code:
Fragment fragment1 = fragmentManager.findFragmentByTag("NavigationFragment_");
if (fragment1 != null) {
fragmentManager.beginTransaction()
.setTransition(TRANSIT_FRAGMENT_FADE)
.remove(fragment1)
.commit();
}
fragmentManager.beginTransaction()
.addToBackStack(backstack)
.setTransition(TRANSIT_FRAGMENT_OPEN)
//.remove(getFragmentManager().findFragmentByTag(NavigationFragment_.class.getSimpleName()))
.add(R.id.fragmentContainer, fragment, fragment.getClass().getSimpleName())
.commit();
I have been searching for a solution for a while without results, so please do not mark this a duplicate.
Thanks in advance.