I have implemented two language in my app "English" and "French" and both of them are working fine individually. When I am trying to check the language change with device language that time getting problem.
Recently my app and device language are "French". Now I am changing the device language from "French" to "English" and then open the app from backstack, app language is still in "French" thats right but In the app, navigation drawer related content changed to "English"
Below is the code for changing language which I have done in GlobalClass
public void changelanguage(String languageToLoad, Context context) {
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
And below is the code for comparing language on MainActivity and Splashscreen
gc = GlobalClass.getInstance()
prefsWrapper = PreferencesWrapper(applicationContext)
sel_langague = prefsWrapper.getPreferenceStringValue(SipConfigManager.LANGUAGE)
println("Language Main : " + sel_langague)
var languageToLoad = ""
if (sel_langague == "0") {
languageToLoad ="en"
} else {
languageToLoad ="fr"
}
gc!!.changelanguage(languageToLoad, baseContext)
Does any one have idea for how can I resolve that problem?
Check this,
and this is my onclick listener of button
and here i am storing the selected language to preference
LocaleHelper class
You have two different options.