Question

my problem is i am using below code for setting locale language dynamically. Its changing the default locale but after calling onResume() while i want to run it immediately as i am at very first page of my app.

locale = new Locale("de");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
Was it helpful?

Solution

EDIT:

Save choosen language in SharedPref:

  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
  SharedPreferences.Editor editor = preferences.edit();
  editor.putString("Lang",ChoosenLang);
  editor.commit();

get Value in onCreate

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
      String Language = preferences.getString("Lang","de");
if (Language != null && !Language.isEmpty()) {
  // Your Language code here

locale = new Locale(Language); // Language=de
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top