Abhishek Abhishek - 3 months ago 7
Android Question

Orientation of activities still changing even after disabling it

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Fantasy">

<activity
android:name="view.StandingsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

<activity
android:name="view.LoginActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

<activity
android:name="view.RegisterActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

<activity
android:name="view.PlayerStandingsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

<activity
android:name="view.ScheduleActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="view.MatchStatsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

<activity
android:name="view.PlayerDetailsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

<activity
android:name="view.PlayerStatsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

<activity
android:name="view.AwardsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

<activity
android:name="view.TeamActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

<activity
android:name="view.AddPlayersActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

</application>


This is a part of my manifest file. I have specified to disable the landscape mode, but still the orientation changes when screen is rotated. What have I missed? Do I have to add any permissions in here? Please help.

Answer

you can override the onConfigurationChanged method of each of your activity to handle orientation changes by yourself..otherwise declaring android:configChanges in your manifest file you are not able to handle them at all..

@Override 
public void onConfigurationChanged(Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   setRequestedOrientation(ActivityInfo."orientation type your preffer");
}