
Suppose I have an Activity that contains two FrameLayouts (let them be called FrameA and FrameB), which, in turn, contain a fragment (let them be called FragmentA1 and FragmentB1, respectively). Now I am committing a series of transactions of individual fragments using code similar to the following ...
getFragmentManager() .beginTransaction() .replace(frameId, fragment) .addToBackStack(null) .commit();
... so I replace FragmentA1 in FrameA with FragmentA2, then I replace FragmentB1 in FrameB with FragmentB2, and then replace FragmentA2 in FrameA with FragmentA3, and then replace FragmentB2 in Frame2 with FragmentB3, and the final state looks like the picture above (where you can see FragmentA3 and FragmentB3 only).
If I correctly understood how the back stack works, pressing back will alternate fragments of fragments between FrameA and FrameB (reflecting how I added them).
Does anyone know if it is possible to selectively output the last transaction to FrameA or FrameB? (i.e. if I clicked "Pop FrameA", then FrameA would be transferred back from FragmentA3 to FragmentA2, and instead, if I clicked "Pop FrameB", then FrameB would be transferred back from FragmentB3 to FragmentB2)
Addition: I know that I can add the last fragment to this FrameLayout using the FragmentManager.findFragmentById(int framelayoutId) method, but calling FragmentTransaction.remove(fragment).commit() removes only the fragment from the view and does not transfer the View back to the fragment, which he previously displayed.
android android-fragments
Adil Hussain Jan 07 2018-12-12T00: 00Z
source share