miviclin miviclin - 1 month ago 10
Android Question

android force lauch activity in landscape mode

I'm trying to launch MyActivity in landscape mode. The problem is that it is currently being launched in portrait mode an then it goes to landscape mode.

I have defined MyActivity in AndroidManifest.xml like this:

<activity
android:name="com.myproject.MyActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleTop"
android:screenOrientation="landscape"
android:taskAffinity="com.myproject"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity>


Is there any way to force the activity to be launched right into landscape mode?

Answer

Try overriding the onConfigurationChanged method.

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }