Reputation:
i am using the following code in my onConfigurationChange mehtod of MainActivity
Locale locale = new Locale(getDefault().getLanguage());
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getApplicationContext().getResources().updateConfiguration(config, null);
And when user selects a different language through Settings the onConfigurationChange method is called but language does not change though other activities opened after MainActivity have the language changed.
My MainActivity is the Activity which remains open throughout the app session
The only way i am able to change language is when the MainAcitivity calls onCreate method but i dont want that as i hav my bluetooth pairing enabled in MainActivity which connects to other bluetooth device whenever onCreate is called i.e only once throughout the app session.
Upvotes: 2
Views: 3678
Reputation: 441
Please check this question: Changing Locale within the app itself
It helps you to change language in all activities and also not from onCreate()
Upvotes: 0
Reputation: 7027
You already answered your own question, when onConfigurationChanged
is triggered, it doesn't automatically update everything. You need to do that manually.
I suggest moving the layout setup from onCreate
to another method and call this new method from both onCreate
and onConfigurationChanged
. Do not forget to also set all the values programatically (i.e. strings) if the strings are only on the layout using @string/xxx.
Upvotes: 1