14

The only thing I can find is to use this:

android:configChanges="orientation"
    android:screenOrientation="portrait"

but it stays as normal. My manifest:

?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:configChanges="orientation"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

DumbCoder
  • 5,696
  • 3
  • 29
  • 40
Synnipoe
  • 200
  • 1
  • 2
  • 13

2 Answers2

36

As seen in the question: I want my android application to be only run in portrait mode?

You should set the configChanges and screenOrientation flags for every activity, and not at the root of your manifest.

So it should look like this:

<activity android:name=".MainActivity"
  android:configChanges="orientation"
  android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>
Community
  • 1
  • 1
Mor Paz
  • 2,088
  • 2
  • 20
  • 38
0

The android:screenOrientation must be in <activity> block. Also android:configChanges is not applicable to <application> but <activity> too.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141