0
  1. How i can change the language in all activities when i chose another language? If i go back to an activity that is previously open it remains with the same configuration. How can refresh that activity too?

i'm using this method:

public void setLocale(String lang) {
    Locale myLocale = new Locale(lang);
    Resources res = getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.locale = myLocale;
    res.updateConfiguration(conf, dm);
    Intent refresh = new Intent(this, Language.class);
    startActivity(refresh);
    finish();
}
  1. How can i save my configurations? If i close the app and open again i want the last configuration.
Veve
  • 6,643
  • 5
  • 39
  • 58
Nuno Pardal
  • 61
  • 1
  • 10

3 Answers3

0

Can you try this solution : Set Locale programmatically

Locale locale = new Locale(lang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
Community
  • 1
  • 1
ThomasV
  • 779
  • 1
  • 5
  • 20
0

You can use shared preference to store the selected language. And every time you come again on same activity first check on shared preference. like this Language switching inside app android

I hope this will help you :)

Community
  • 1
  • 1
0
myLocale = new Locale("en");
        Resources res = getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        conf.locale = myLocale;
        res.updateConfiguration(conf, dm);

This worked for me. You can change the "en" to a different language is you want. I had the same problem as you did but eventually found this code. Hope it helps you too. Of course you can put this in a button with clicklistener if you want or at start up. This code worked everywhere for me. Good luck.