I have an Android app, I want to make the tablet (sw600dp and higher) display in landscape mode and the phone to display in portrait mode, so I call onCreate of my BaseActivity class
boolean isTablet= getResources().getBoolean(R.bool.isTablet);
if (isTablet) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
And how I put "isTablet" in the bools.xml file and put it in
values for phone
<resources>
<bool name="isTablet">false</bool>
</resources>
values-sw600dp for tablet
<resources>
<bool name="isTablet">true</bool>
</resources>
And in AndroidManifest I use
android:screenOrientation="nosensor"
just unplug the device’s orientation sensor.
It seems that my approach works fine (Landscape for tablet and Portrait for phone), but the problem arises when I launch my application on Nexus 7 - my actions are created twice . These steps are:
, setRequestedOrientation() ( 2 ). . AndroidManifest, :
android:screenOrientation="@integer/orientation"
:
SCREEN_ORIENTATION_LANDSCAPE = 0
SCREEN_ORIENTATION_PORTRAIT = 1
"" integers.xml
<resources>
<integer name="orientation">1</integer>
</resources>
-sw600dp
<resources>
<integer name="orientation">0</integer>
</resources>
, , , AndroidMenifest "" , values-sw600dp. , 2 . ? ? .