Locale is no updating in release bundle,but it is working in debug apk. I am using targetSdkVersion 29 and androidx.appcompat:appcompat:1.3.0-alpha02
In MainActivity
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(LocaleManager.updateResources(base));
}
public class LocaleManager {
public static String TAG = "LocaleManager";
public static String LOCALE_HI = "hi_IN";
public static String LOCALE_EN = "en_US";
private static String lan_str;
private static String country_str;
public static void setlan(String str)
{
String val[] = str.split("_");
LocaleManager.lan_str = val[0];
LocaleManager.country_str = val[1];
}
public static String getlanguage()
{
return LocaleManager.lan_str+"_"+LocaleManager.country_str;
}
public static Context updateResources(Context context) {
if(lan_str == null || country_str == null)
return context;
Locale locale = new Locale(lan_str,country_str);
Locale.setDefault(locale);
Resources res = context.getResources();
Configuration config = new Configuration(res.getConfiguration());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLocale(locale);
config.locale = locale;
} else {
config.locale = locale;
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N){
context = context.createConfigurationContext(config);
} else {
res.updateConfiguration(config, res.getDisplayMetrics());
}
return context;
}
}
I am doing re-lunch MainActivity after change language, but locale not update.
Finally i got solution for locate added this inside the android block of app build.gradle
referenced from https://www.mmbyte.com/article/55895.html . Thanks