I have four Fragments: A, B, C, D. Now I am moving from A --> B so my code will be
from A to B
getActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new B())
.addToBackStack("A")
.commit();
Now from B to C so code will be
getActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new C())
.addToBackStack("B")
.commit();
Now from C to D. But I don't want to include C in backstack because on back press I don't want C fragment to be shown.
getActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new D())
.commit();
Now when I press Back button it will work perfectly upto A. Now if I repeat same process again. Now again on back press From D Fragment, I will be sent directly on A fragment instead of B fragment. Can you please figure it out the mistake that I am doing in above code?
Here is the code of BackStackChangedListener.
You have to provide same String value for addToBackStack for single Stack.