benruty benruty -4 years ago 39
Java Question

How to save app orientation State when launched

I am working on a media player android app. I have set portrait and landscape layouts in my res folder for different activities. I want a single orientation for each individual launch instance. This means that if the user launches the app in portrait mode, it should show my only my portrait layout till its destroyed or if its launched it landscape mode, my landscape layouts would be disclosed. Is there a way around this?

This is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.musicianfocus.ben.wordedfm">
<uses-permission android:name="android.permission.INTERNET"/>

<supports-screens
android:smallScreens="false"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"
/>
/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<category android:name="android.intent.category.LAUNCHER" />
<intent-filter>

<action android:name="com.musicianfocus.ben.wordedfm.actionPLAY" />
</intent-filter>
</activity>
<service android:name=".RadioService"
android:enabled="true"/>

</application>

</manifest>

Answer Source

you can use this

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download