I am facing a strange issue.
I have an Android application with 2 languages, en and el
The English values are stored in values / strings.xml and the Greek in values-el-rGR/ strings.xml
If you select Greek and reopen the application, Greek is the selected language and all the app details are in Greek.
But when I am choosing something from the list the app gets the string value from the default with the result in the next screen being empty
To mention that this happens only the first time when you open the app and the language is Greek.
If I go back to the main Activity and try again then is ok.
When the app starts at main activity I call loadLocale();
public void loadLocale (){
SharedPreferences prefs = getSharedPreferences("Settings", Activity.MODE_PRIVATE);
String languagestring = prefs.getString("My_Lang", "");
languageSelection = languagestring;
setLocale(languagestring);
}
private void setLocale (String lang){
Locale locale = new Locale (lang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
SharedPreferences.Editor editor = getSharedPreferences("Settings", MODE_PRIVATE).edit();
editor.putString("My_Lang", lang);
editor.apply();
if (lang.equals("el")){
language.setImageResource(R.drawable.gr);
}
else if (lang.equals("en"))
{
language.setImageResource(R.drawable.eng);
}
}
What I am doing wrong?