public void setRequestedOrientation(int requestedOrientation) is used to change the desired orientation of this activity. If the activity is currently in the foreground or otherwise impacting the screen orientation, the screen will immediately be changed (possibly causing the activity to be restarted). Otherwise, this will be used the next time the activity is visible.
Where requestedOrientation is an orientation constant: ActivityInfo.screenOrientation.
Related: How to set orientation of activity/application in AndroidManifest.xml