I have an application with a single Activity and two fragments. The desired behavior is (user interaction highlighted in blue color):
In portrait
In landscape
My current solution is:
Layout in landscape
FrameLayout
ContainerRed(FrameLayout)
ContainerYellow(FrameLayout)
Layout in portrait
LinearLayout
ContainerRed(FrameLayout weight=1)
ContainerYellow(FrameLayout weight=1)
When the user clicks the green button I do the following transactions:
- In portrait: Remove FragmentA, add FragmentB to containerYellow, addToBackstack
- In landscape: add FragmentB to contanerYellow, addToBackstack
This implements a correct behaviour except if you rotate the device after a transaction, for example, if you are in portrait, go to the screen B1 and then rotate the device to landscape the FragmentA slot is empty.
Additionally if you are in the screen B2 and rotate the screen to portrait the FragmentA appears in the background of the FragmentB.
How can I solve that? thanks