I want to change the orientation programmatically while running my Android App, with these lines of code:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTA
In AndroidManifest file add android:configChanges="orientation" for the activity you want to handle this orientation
android:configChanges="orientation"
In activity use onConfigurationChange overrided method. Do task you want to handle in orientation change.