I have created 4 languages for the app. I can change the Lauaguage, ok, but if close the app and then start I it again, the app starts atfirst with the default string.xml.
How to let the app starts with the last selected Language ?
should I call the the methode by OnCreate in the mainActivity ?
@SuppressWarnings("deprecation")
public void setLocale(String lang) {
Locale myLocale = new Locale(lang);
DisplayMetrics dm = getResources().getDisplayMetrics();
Configuration conf = getResources().getConfiguration();
conf.locale = myLocale;
getResources().updateConfiguration(conf, dm);
Intent refresh = new Intent(this, Languages.class);
startActivity(refresh);
/* "en" = English
"hi" =Hindi
"fr" =French
"it" =Italian
"de" =German
"es" =Spanish
"ja" =Japanese
"ko" =Korean
"nl" =Dutch
"pt" =Portuguese
"ru" =Russian
"zh" =Chinese
"ar" = arabic
*/
}
How can the user change the default language ?
Why don't you store the selected language in shared preferences? That way you can always check for the selected language when your app starts, and then load the appropriate language file.