Skip to main content
Logo Appt Light

Screen orientation on Android

Apps should adapt to the preferred display orientation of the user. Most apps restrict the screen to portrait orientation, but they should also support landscape orientation. Some users have their devices mounted in a fixed orientation (e.g. on the arm of a wheelchair). Therefore, apps need to support both orientations.

On Android, make sure that the android:screenOrientation attribute is not used anywhere.

Open Android Studio and press the Shift key twice to open the search dialog. Search for “android:screenOrientation”. In case there are search results, remove the attribute.

You probably need to make additional code adjustments to make sure the all orientations are working as intended.

To listen to orientation changes, add android:configChanges="orientation" to your manifest. Then, override the onConfigurationChanged to receive configuration notifications. Use the orientation property of the Configuration object to check the new orientation.

override fun onConfigurationChanged(newConfig: Configuration) {
    super.onConfigurationChanged(newConfig)

    when (newConfig.orientation) {
        Configuration.ORIENTATION_PORTRAIT -> {
            // Portrait logic
        }
        Configuration.ORIENTATION_LANDSCAPE -> {
            // Landscape logic
        }
        else -> {
            // Ignored
        }
    }
}

Feedback?

Let us know!