While developing an Android app, I've found two ActivityInfo attributes for setting the screen orientation.
The attributes having USER are as follows:
The attributes having SENSOR are as follows:
What is the difference between the SCREEN_ORIENTATION_USER and SCREEN_ORIENTATION_SENSOR?
Screen Orientation, also known as screen rotation, is the attribute of activity element in android. When screen orientation change from one state to other, it is also known as configuration change.
If you want to manually handle orientation changes in your app you must declare the "orientation" , "screenSize" , and "screenLayout" values in the android:configChanges attributes. You can declare multiple configuration values in the attribute by separating them with a pipe | character.
When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates them. Android does this so that your application can reload resources based on the new configuration.
As with almost all smartphones, Android supports two screen orientations: portrait and landscape. When the screen orientation of an Android device is changed, the current activity being displayed is destroyed and re-created automatically to redraw its content in the new orientation.
From source
The attributes having USER are as follows.
SCREEN_ORIENTATION_USER
Use the user's current preferred orientation of the handset. Corresponds to SCREEN_ORIENTATION_USER.
SCREEN_ORIENTATION_USER_LANDSCAPE
Would like to have the screen in landscape orientation, but if the user has enabled sensor-based rotation then we can use the sensor to change which direction the screen is facing. Corresponds to SCREEN_ORIENTATION_USER_LANDSCAPE.
SCREEN_ORIENTATION_USER_PORTRAIT
Would like to have the screen in portrait orientation, but if the user has enabled sensor-based rotation then we can use the sensor to change which direction the screen is facing. Corresponds to SCREEN_ORIENTATION_USER_PORTRAIT.
The attributes having SENSOR are as follows.
SCREEN_ORIENTATION_SENSOR
Orientation is determined by a physical orientation sensor: the display will rotate based on how the user moves the device. Ignores user's setting to turn off sensor-based rotation. Corresponds to SCREEN_ORIENTATION_SENSOR.
SCREEN_ORIENTATION_SENSOR_LANDSCAPE
Would like to have the screen in landscape orientation, but can use the sensor to change which direction the screen is facing. Corresponds to SCREEN_ORIENTATION_SENSOR_LANDSCAPE.
SCREEN_ORIENTATION_SENSOR_PORTRAIT
Would like to have the screen in portrait orientation, but can use the sensor to change which direction the screen is facing. Corresponds to SCREEN_ORIENTATION_SENSOR_PORTRAIT.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With