I'm changing the language from English to Arabic programmatically using this function :
private void setLocale(String lang) {
Locale myLocale = new Locale(lang);
Resources res = getContext().getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
conf.setLocale(new Locale(lang));
Locale.setDefault(myLocale);
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(getContext(), MainActivity.class);
getActivity().finish();
startActivity(refresh);
}
The language is changing,however when using
Locale.getDefault().getLanguage();
or
Resources.getSystem().getConfiguration().locale.getLanguage();
I'm still getting English ( en ) instead of the expected value ar although the displayed language is arabic.
Any idea why it's still returning en?