I want to have 2 different orientation modes depending on the device - if device screen is Extra Large, the orientation should be LANDSCAPE and if device screen is smaller, the orientation should be PORTRAIT.
I have made the following check:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set orientation for tablets and phones
if (isXLarge()) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
setContentView(R.layout.activity_main);
}
The manifest entry for the activity is:
<activity
android:configChanges="keyboardHidden"
android:launchMode="singleTop"
android:theme="@android:style/Theme.NoTitleBar"
android:name=".MyActivity"/>
It works fine on mobile phones, however on the Motorola Xoom tablet with Android 3.2 this does not work correctly.
If we assume that the tablet is physically hold in portrait mode, the following sequence of actions happens:
- Activity is created and displayed in Portrait Mode - this is displayed visually for half-second
- Activity is destroyed and recreated in Landscape Mode.
The problem is that there is always the middle transition in the orientation in which the tablet is currently held physically and after that the activity is recreated with the desired orientation.
Thank you for any information or advice about the problem and please tell me if you need more details.
The method isXLarge() returns correctly the type of display