1

I am trying to prevent myy app orientation to landscape to portrait or vice versa when I lock the screen by clicking screen rotation to off.I saw that once I deselect screen rotation, the entire screen locks up including the screen of the apps I have on my device except for my app where orientation change still triggers landscape portrait recognition even when locked.How do I go around it? DoI need to set something in android manifest to make it work in accordance with the screen rotation ?

Thanks!

  • May I ask you why you need/want to prevent the orientation switch after the screen lock? – STT LCU Jan 08 '14 at 16:09
  • I want it to adhere to the normal behavior like all the other apps, when you deselect screen rotation/lock the device screen, all the other apps remain in the particular orientation –  Jan 08 '14 at 16:16
  • This post should help you: http://stackoverflow.com/questions/4697631/android-screen-orientation – waqaslam Jan 08 '14 at 16:17

2 Answers2

0

You can set either add android:screenOrientation="portrait" or android:screenOrientation="landscape" parameter to your AndroidManifest.xml.

edit: You can also "lock" screen orientation programmatically using setRequestedOrientation (int requestedOrientation)

XorOrNor
  • 8,868
  • 12
  • 48
  • 81
  • I don't want to restrict the behavior of my app. It works fine as is.I just want it to lock the orientation when I lock my whole device by unclicking screen rotation ,I want my app to be just like the other app and remain in the orientation it is whether landscape or portrait once the screen rotation button is unselected on the device –  Jan 08 '14 at 16:15
  • where do I do it programmatically? in my main activity? –  Jan 08 '14 at 16:18
  • I the Activity that you want to lock. See this topic for more: http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android – XorOrNor Jan 08 '14 at 16:21
  • that didn't help. Can you provide a sample code for say main activity with oncreate methods, very generic way to do this –  Jan 08 '14 at 16:39
0

If you want to lock orientation when user locks it in the system you need to add android:screenOrientation="user" in your activity tag

Hellboy
  • 1,052
  • 6
  • 12