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>
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With