The screenOrientation is the attribute of activity element. The orientation of android activity can be portrait
, landscape
, sensor
, unspecified
etc. You need to define it in the AndroidManifest.xml
file. For example:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
Value | Description |
---|---|
unspecified |
It is the default value. In such case, system chooses the orientation. |
portrait |
taller not wider |
landscape |
wider not taller |
sensor |
orientation is determined by the device orientation sensor. |
One of the key features of modern smartphones is their ability to switch screen orientation, and
Android is no exception. Android supports two screen orientations: portrait and landscape. By
default, when you change the display orientation of your Android device, the current activity that is
displayed automatically redraws its content in the new orientation. This is because the onCreate()
method of the activity is fired whenever there is a change in display orientation.
NOTE: When you change the orientation of your Android device, your current
activity is actually destroyed and then recreated.
One of the most common “solutions” to dealing with orientation changes is to not deal with them. You can do this by setting the android:configChanges
flag on your Activity in AndroidManifest.xml
as shown below:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|keyboardHidden" >