Screen orientation - Android
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.
<activity
android:name=".ApptActivity"
android:screenOrientation="portrait" <!-- Remove -->
android:configChanges="orientation" <!-- Add -->
</activity>
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
when (newConfig.orientation) {
Configuration.ORIENTATION_PORTRAIT -> {
// Portrait logic
}
Configuration.ORIENTATION_LANDSCAPE -> {
// Landscape logic
}
else -> {
// Ignored
}
}
}