I have an activity with two FrameLayouts, each with a fragment. But when doing a backpress first the fragmentA returns to its previous state, and after another backpress the fragmentB returns to its previous state.
I want when backpressing both FragmentA and FragmentB to return to their previous state at the same time.
Here the code:
mFragmentService.replaceAndAddToBackStack(FragmentA.newInstance(), R.id.container_top);
mFragmentService.replaceAndAddToBackStack(FragmentB.newInstance(), R.id.container_bot);
public void replaceAndAddToBackStack(Fragment fragment, @IdRes int idRes) {
mFragmentManager
.beginTransaction()
.replace(idRes, fragment)
.addToBackStack(fragment.getClass().getName())
.commit();
}
Any ideas?
Navigation through the backstack in the activity:
And to go back it would be something like doing this twice from the activity or from the fragment:
mFragmentManager.popBackStack();