0

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>
benruty
  • 89
  • 1
  • 1
  • 7

4 Answers4

1

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>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

This should work disable the change of orientation programmatically :)

RaffoSorr
  • 405
  • 1
  • 5
  • 14
0

Here's a question which could help you! Instead of changing it with a button you could safe it in a DB or file of settings you want to safe, and load them with a filereader.

0

This is not an exact solution but a Jugaad , create 2 activities, one for landscape and one for portrait, when user starts your app , check the orientation programmatically, for example if user starts your app in portrait mode, then start activity of portrait mode otherwise landscape. This solution will have a redundant code but it will work based on your requirement.