I have an activity with two FrameLayouts, each with a fragment. But when doing a backpress first the fragment returns to its previous state, and after another backpress the fragment returns to its previous state.
I want to make backpress the two FragmentA and FragmentB back 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?