'Changing the Orientation Smoothly for SDK from App
I know the question related to orientation has been asked multiple times, but I am facing some weird issue. I am working on one SDK that has some Activity which can be opened from the App, The SDK asks for the orientation values from the App and I am updating the orientation in onCreate() of the Activity by setting:
requestedOrientation = orientation
It works perfectly when I am holding the device in the same orientation as the orientation is set by App. But If I am holding the device in portrait mode and setting the requestedOrientation to LANDSCAPE then my screen flickers, 1st it shows the portrait screen and then goes to landscape.
In manifest I have set the configChanges to android:configChanges="keyboard|keyboardHidden|screenSize"
I have separate layouts for both the orientations. Let me know, if anything else is also required.
Solution 1:[1]
You should set requested orientation based on configuration changes
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else if...
}
If you want to support portrait and reverse portrait together, do it with SCREEN_ORIENTATION_SENSOR_PORTRAIT.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sumit Kumar |
