top of page
Search

Support orientation changes in your Android Application

  • Writer: Bunyamin Basoglu
    Bunyamin Basoglu
  • Feb 21, 2022
  • 1 min read

How to support orientation changes

As most you have already know when orientation changed in a device, the current activity will be destroyed and recreated again with your applications default behavior. If your application does not need landscape orientation you can just set your activity orientation to portrait. So you don't have to consider about orientation changes anymore. To achieve this you need to set screenOrientation of your activity to portrait in your AndroidManifest.xml as seen below.

<activity
    ...
    android:screenOrientation="portrait"
    ...>
</activity>

If you do not want to use your application only in portrait mode then you need to define a configuration changes list to your activity. Defining this list of configuration changes means that the activity will handle these itself. When any of these changes in that defined list occur at runtime, the activity will not be restarted again. Instead, onConfigurationChanged() method will be called.

<activity
    ...
    android:configChanges="keyboardHidden|orientation|screenLayout |screenSize|layoutDirection|uiMode"
    android:screenOrientation="fullSensor"
    ...>
</activity>


 
 
 

Comments


bottom of page