lock/unlock orientation

Matt picture Matt · Jun 15, 2011 · Viewed 8.3k times · Source

To lock my orientation to portrait, I use:

activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

I'm unsure what flag tells the activity to go back to relying on the device orientation. I imagine it is one of these:

SCREEN_ORIENTATION_FULL_SENSOR
SCREEN_ORIENTATION_SENSOR
SCREEN_ORIENTATION_UNSPECIFIED
SCREEN_ORIENTATION_USER


On another note, why isn't the android documentation open source? The documentation is completely lacking. Very few of the functions and flags have useful descriptions.

Answer

Arthur Shipkowski picture Arthur Shipkowski · Jun 15, 2011

Per http://developer.android.com/reference/android/R.attr.html#screenOrientation (screenOrientation being what those values are linked to if you dig through the documentation), SCREEN_ORIENTATION_SENSOR or SCREEN_ORIENTATION_FULL_SENSOR will do it, depending on how much flexibility you want -- however, I suspect what you really want is to go back to the default setting, which is SCREEN_ORIENTATION_UNSPECIFIED so that it goes back to the system defaults, including any the user set.