1

I'm using default piece of code in all my projects, in BaseActivity in onCreate():

Locale locale = new Locale("ru");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());

I tried put here like new Locale("ru", "RU") - no difference. The weird part that this problem occurs only in android 5.02 NOT 5.0,5.01. Also there is exist such problem so my assumptions there are were significant changes in locale api.

EDIT: I'm restarting whole app after changing locale in settings

ar-g
  • 3,417
  • 2
  • 28
  • 39
  • I have the same issue. Here is the fix for this. [Here is the fix for this](http://stackoverflow.com/questions/2900023/change-language-programmatically-in-android/43938564#43938564) – Maxim Petlyuk May 12 '17 at 13:13

1 Answers1

0

you must restart the activity, but be aware this won't update the already opened activity(the alreardy in the back stack) , i usually update then call the main activity with the following properties in manifest

<activity
        android:name=".activities.SplashActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop" #the important
        >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

funiction to update the lang

public static void updateLanguage(Context ctx, String lang, boolean goToHomeScreen) {
    Configuration cfg = new Configuration();
    if (!TextUtils.isEmpty(lang))
        cfg.locale = new Locale(lang);
    else
        cfg.locale = Locale.getDefault();

    ctx.getResources().updateConfiguration(cfg, null);

    if (goToHomeScreen) {
       Intent intent = new Intent(ctx, HomeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    ctx.startActivity(intent);
    }
}
zaPlayer
  • 787
  • 5
  • 24