I want to lock screen orientation to portrait for tablet. and I implemented this in onCreate() method. However, the scree orientation doesn't keep portrait and it's causing unnecessary flicker and re-creation of the activity. I don't know why. Please help me. The dialog shows when dialogUiState is not null.
if (DeviceUtils.isTablet(this) && dialogUiState != null) {
requestedOrientation = (ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT)
}
object DeviceUtils {
@JvmStatic
fun isTablet(context: Context): Boolean {
val configuration = context.resources.configuration
val screenLayoutSize = configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
return screenLayoutSize > Configuration.SCREENLAYOUT_SIZE_NORMAL
}
}
I want to know how to lock the screen orientaion to portrait for tablet.
I want to lock screen orientation to portrait for tablet. and I implemented this in onCreate() method. However, the scree orientation doesn't keep portrait and it's causing unnecessary flicker and re-creation of the activity. I don't know why. Please help me. The dialog shows when dialogUiState is not null.
if (DeviceUtils.isTablet(this) && dialogUiState != null) {
requestedOrientation = (ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT)
}
object DeviceUtils {
@JvmStatic
fun isTablet(context: Context): Boolean {
val configuration = context.resources.configuration
val screenLayoutSize = configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
return screenLayoutSize > Configuration.SCREENLAYOUT_SIZE_NORMAL
}
}
I want to know how to lock the screen orientaion to portrait for tablet.
Share Improve this question edited Nov 29, 2024 at 2:04 John asked Nov 28, 2024 at 9:45 JohnJohn 631 silver badge9 bronze badges 2 |1 Answer
Reset to default 2You should use SCREEN_ORIENTATION_PORTRAIT
to ignore sensor.
According to the docs, SCREEN_ORIENTATION_SENSOR_PORTRAIT
can still use the sensor:
Would like to have the screen in portrait orientation, but can use the sensor to change which direction the screen is facing.
android:configChanges =
andandroid:screenOrientation=
? My goal is that the screen orientation keeps portrait even though I rotate the screen. – John Commented Nov 28, 2024 at 16:18