I want to be informed in my Application class when the system language is changed. My Application class:
class MyApp : Application() {
override fun onConfigurationChanged(newConfig: Configuration?) {
Log.d("yyy", "onConfigurationChanged, old locale " + resources.configuration.locale + " new locale " + newConfig?.locale)
super.onConfigurationChanged(newConfig)
}
}
I would assume that, if comparing the current locale to the new locale before calling super.onConfigurationChanged(newConfig)
, they would differ, but when I set the system locale to e.g. En_US
in the Android settings app, resources.configuration.locale
already returns En_US
(and the new config does too), so there is no way for me to check if the locale way actually changed.
My solution would be to save the selected locale in the applications onCreate()
and compare it with the new locale in onConfigurationChanged()
.
- Is there a more elegant way?
- Why does
onConfigurationChanged
behave that way?