I'm developing an app with multi-language feature, It supports landscape
and reverseLandscape
orientations. Its working fine up-to Marshmallow devices.
But in Nougat+
devices, when I change orientation from landscape to reverse landscape,it seems locale gets resets to default one. After this, all the newly creating Activity
, Fragment
, Dialog
having English language.
BaseActivity
This is what my simplified base activity looks like
abstract class LocaleBaseActivity : AppCompatActivity() {
public override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(refreshLocale(newBase, LanguageVO.getInstance().LocalizationCode[0]))
}
fun refreshLocale(context: Context, lang: String): Context {
val locale = Locale(lang.toLowerCase())
val configuration = context.resources.configuration // getBaseContext().
configuration.locale = locale
configuration.setLocale(Locale(lang.toLowerCase()))
context.resources.updateConfiguration(configuration, context.resources.displayMetrics)
Locale.setDefault(locale)
return context
}
}