1

In my manifest file, I set

    android:screen orientation="portrait" 

for my MainActivity. I did this so that my initial tutorial can work well. After the initial tutorial has concluded, I now want my MainActivity to behave normally ie when the user rotates the device let it change by itself(the default behaviour). Is there a way to that

Michael Okoli
  • 4,308
  • 2
  • 14
  • 20

3 Answers3

4

Remove android:screenorientation="portrait" from Manifest First .

From Run-time

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Also add this in your manifest file (under activity):

android:configChanges = "orientation"

Change orientation at runtime

http://techblogon.com/android-screen-orientation-change-rotation-example/

Community
  • 1
  • 1
IntelliJ Amiya
  • 73,189
  • 14
  • 161
  • 193
1

remove android:screenorientation="portrait" from your manifest, and make sure rotation is on in your device

Ravi
  • 33,034
  • 19
  • 115
  • 176
1

Remove android:screenOrientation="portrait" from manifest file and make sure your device setting isint set to "locked rotation"

also android:screenOrientation="portrait" works for whole manifest file level and also it works individually for activity tag level in manifest, so if android:screenOrientation="portrait" is added in activity tag level , remove it from there too.