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.