I have the util class to get the devices rotation (example below). It operates over application context. When I have phone in portrait mode, it returns PORTRAIT. However, when I rotate phone to landscape, then this method still returns PORTRAIT.
The same thing happens when I have values and values-land with a boolean flag indicating landscape that I read on demand.
It looks like that application context's configuration remains the same through the whole process lifetime. E.g. it keeps the configuration it started with.
Can anybody confirm this please? And if so, how should I approach this issue?
@Singleton
class DeviceInfo @Inject constructor(private val context: Context) {
enum class DeviceOrientation {
PORTRAIT, LANDSCAPE
}
fun getOrientation(): DeviceOrientation {
val orientation = context.resources.configuration.orientation
return when (orientation) {
Configuration.ORIENTATION_LANDSCAPE -> DeviceOrientation.LANDSCAPE
else -> DeviceOrientation.PORTRAIT
}
}
}