I want to change the orientation programmatically while running my Android App, with these lines of code:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
They work so far, but the main problem is that the whole activity is reloaded when the screen orientation changes, and I don't want that. Is it possible? Thanks.
EDIT: OK, after I while I found out what I was missing. I had to include also "screenSize" in the configChanges property, so having
android:configChanges="orientation|screenSize"
solved the whole thing.
See the edit by @luisfer. For targeting Android 3.2 and above, you need BOTH
android:configChanges="orientation|screenSize"
http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange