I implement the app which has two layout for landscape and portrait mode. The layout for landscape is in the layout-land. I have the fragment1 for portrait layout and fragment2 for landscape layouts. I override the onCreateView in each fragment.
I have static variable to know the current fragment. I assgined in the onCreateView (1 for fragment1 and 2 for fragment2).
My problem is that the static value is still 1 when the orientation is landscape mode.
I debugged the orientation of application. When I change orientation portrait into landscape, fragment2's onCreateView method called first and then the fragment1's onCreateView method called again. The static value has overridden.
I don't know why did fragment1 onCreateView method call after the fragment2 called? I want to assign the right value for right fragment.
Sorry for my bad English.
Thanks.
You don`t need to save something! Just let your activity handle the orientation change. In AndroidManifest.xml put this
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize" >
</activity>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With