I have application which uses fragments. Depending on screen size and orientation I’m displaying different layouts:
1. layout-fragment – list of choices
2. layout-fragment – display selected choice
I have problem with handling orientation change in large screen. In portrait mode I’m displaying both fragments in one layout but in landscape mode if user has chosen to display sth I’m only displaying 2nd fragment activity. When in this state orientation is changed back to portrait mode I would like to display both fragments again but instead I’m displaying again 2nd layout fragment activity.
I understand that it’s android activity management but what is the best way to make it work as I would like to have (always display 1 and 2 fragment in portrait mode)?
Thanks for any suggestions!
This is because your second activity (showing only one frag) is re-created on orientation change.
What you can do here is to check orientation in your onCreate, if portrait – launch Activity_1 with suitable intent so that it can start second frag for correct details. Naturally you must also edit Activity_1 to check for this intent in onCreate..
Some example code where intent has action ACTION_VIEW and uri for detail object.
Activity_2 (one fragment – should only be used in landscape)
Activity_1 (showing two fragments if orientation allows
Recommended orientation check:
Check orientation on Android phone