I'm having trouble with changing the app language manually, in the app, I offer users the ability to change the app's language to their preferred, the code below works fine even in Android
(Pixel 3 Emulator), but for some reason, it doesn't work on all Samsung devices
Context context = LocaleUtils.setLocale(getApplicationContext(), languageCode);
Resources resources = context.getResources();
Locale myLocale = new Locale(languageCode);
DisplayMetrics dm = resources.getDisplayMetrics();
Configuration conf = resources.getConfiguration();
conf.locale = myLocale;
resources.updateConfiguration(conf, dm);
Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(
getBaseContext().getPackageName());
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
Application class:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
LocaleUtils.onAttach(base, Locale.getDefault().getLanguage());
MultiDex.install(this);
}
on each Activity:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(ViewPumpContextWrapper.wrap(LocaleUtils.onAttach(newBase)));
}