I'm changing locale of my app programmatically using the following method. It works fine but when I start an already existing singleTask activity using Intent.FLAG_ACTIVITY_CLEAR_TOP flag. Then application loses the layout direction but translation is correct. For example, if application language is Arabic then all views direction is changed to English locale (left-to-right). What could be the reason?
I'm calling following method in attachBaseContext of BaseActivity and Application class.
public Context createLocaleConfiguration(Context context,String language) {
Locale newLocale = new Locale(language);
Resources res = context.getResources();
Configuration configuration = res.getConfiguration();
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
LocaleList localeList = new LocaleList(newLocale);
LocaleList.setDefault(localeList);
configuration.setLocales(localeList);
configuration.setLayoutDirection(newLocale);
context = context.createConfigurationContext(configuration);
} else {
configuration.setLocale(newLocale);
configuration.setLayoutDirection(configuration.locale);
Locale.setDefault(newLocale);
context = context.createConfigurationContext(configuration);
}
return context;
}
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleManager.getInstance().createLocaleConfiguration(newBase,language));
}
Any ideas would be appreciable. Thanks