In 'Landscape' mode I have two FrameLayouts controlled by One Activity and utilizing two Fragments. In 'Portrait' mode I have one FrameLayout controlled by One Activity, on Selecting a Line I call another activity to display the detail using a detail fragment
In the 'Portrait' detail activity I have the following check for orientation in the onCreate() method.
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { finish(); return; }
The above works well but,
A problem arises though when I have a 'small' device. In this case in 'Landscape' mode I don't want the two fragment view, rather I want to behave like the 'portrait' view. However since the device is in fact in 'Landscape' when the detail activity launches it automatically finishes.
So the questions is what is the best way of handling this?
Preform an additional check for screen size before your check for the orientation. Considering that a small device has a width of 500 pixels and a height of 600 pixels, you would do something like this.
or create a custom resource with a bool value (from google io 2012)
NOTE: You have to define a minimum screenwidth (sw320dp) for which you will consider a screen not to be small (link with more info)
The advantage is that you can read this value at runtime & you can have special cases for special resource qualifiers... E.g. you can read this value at runtime by calling in your activity:
You can even use this boolean resource in your manifest like so, to start a completely different activity for small screens
This way you can simply use an Activity for the normal case (android:enabled="@bool/normal_screen") and use a special activity for small screen android:enabled="@bool/small_screen"
WARNING: This method will not work on newer devices since honeycomb. You can read why this method is not allowed anymore or read about working similar solution