Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

screen orientation inherited by child activity

I have a Base activity(extends AppCompactActivity) which is extended by all the activities. My question is if I set android:screenOrientation="portrait" from the Manifest file to the base activity, why is it not set to all the activities that are extending this activity. This is my manifest file

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".LoginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".BaseActivity"
        android:screenOrientation="portrait"/>
    <activity android:name=".OtpActivity"></activity>
</application>
like image 875
srb1991 Avatar asked Sep 07 '18 08:09

srb1991


2 Answers

If you want to set orientation for all the child activity, perhaps it's better to use code as below on the base activity

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

In the Manifest, it is targeting the exact activity instantiated e.g. if it is for .BaseActivity, then only the actual .BaseActivity launch will have it's xml configuration. The value set in the xml doesn't apply beyond the code inheritance hierarchy, but instead each activity launch will need to have it's own tag in manifest.xml. Inheritance doesn't apply here in the AndroidManifest.xml.

like image 103
Elye Avatar answered Nov 15 '22 06:11

Elye


Note: In android:screenOrientation="portrait" is properties of every screen or activity which is register in manifest file so if you dont mention this property in every activity in the manifest then it will take default so we have to mention this property for each and every activity, even if activity extend by other activity which mentions this property Inheritance doesn't apply here in the AndroidManifest.xml.

like image 28
Ashutosh Avatar answered Nov 15 '22 06:11

Ashutosh