spyfx
spyfx

Reputation: 1351

OnConfigurationChanged is not called after locale config change

What I want to do is to provide a simple language change for the user within the app. The text of the current view as well as the Back Stack should be replaced with the strings of the selected language. I have just written the following code snippet which does his job fine:

private void setLocale(Locale locale) {
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
}

After some researching I figured out, that every activity should automatically refreshes itself after the locale configuration has been changed - but it doesn't in my case. The current view as well as the whole Back Stack have still the default locale - they just change after reopening the activity.

I have already added the attribute android:configChanges="locale|layoutDirection" to my AndroidManifest.xml so that won't do the trick.

Do you guys have any suggestions? Or do I have the wrong purpose for solving this problem eitherway?

EDIT
Okay it seems like OnConfigurationChanged() only triggers by changing the language device-wide in the android settings?
Is there any other way to refresh EVERY active activity (current and back stack) after changing the language in my app?

Upvotes: 6

Views: 2549

Answers (1)

Love Garg
Love Garg

Reputation: 406

I think if you create a Receiver who has this event filter

<action android:name="android.intent.action.LOCALE_CHANGED"/> will give you an event when device locale is changed then you can refresh all activity you want. For refreshing you can look into this. Hope it will solve your issue.

Upvotes: 0

Related Questions