I'm using this below method to change the language of the app by passing the language code as string.
When I change the screen orientation the language rests to default language and all views resets too.
public String setLocale(String lang) {
Locale myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, Login.class);
startActivity(refresh);
finish();
return lang;
}
I tried to use onSaveInstanceState
and onRestoreInstanceState
, but I don't know how to make all these methods work together.