-1

How do I disable portrait/landscape mode after the app is started? Say, if I start the app in landscape mode, it stays in landscape mode. If I start it in portrait mode, it stays in portrait mode?

Thank you

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Dawg85
  • 61
  • 1
  • 5

4 Answers4

1

Please refer Below Link

orientation lock in android programmatically

You can maintain your preference to stay in particular landscape/protrait mode

Community
  • 1
  • 1
bindal
  • 1,940
  • 1
  • 20
  • 29
0

just do the folllowing this will start activity in portrait mode.

In the manifest, set this for all your activities:

<activity android:name=".YourActivity"
    android:configChanges="orientation"
    android:screenOrientation="portrait"/>

see here more discussion

Community
  • 1
  • 1
A.s.ALI
  • 1,992
  • 3
  • 22
  • 54
0

You might create two acitivties which is either started in landscape or portrait mode. To disable the opposite, do as already said.

android:screenOrientation="portrait"

jle
  • 686
  • 1
  • 8
  • 24
0

Simple Once your app is started get the orientation of the device.Then set that orientation to all your activities.

In your first activity's onCreate method get the current orientation of the device like this

 int orientation = getResources().getConfiguration().orientation;
 setRequestedOrientation(orientation);

This will set the orientation for the current activity only.But if you want to set the whole app to this mode then try this Create a helper class like this

 Class ActivityHelper{

      public static void setOrientation(Activity activity,int orientation){
          activity.setRequestedOrientation(orientation);
      }
 }

in your Everyactivity after setContentView call

ActivityHelper.setOrientation(this,orientation);//Keep orientation as a static variable
Rajesh Gosemath
  • 1,812
  • 1
  • 17
  • 31