Search code examples
androiduser-interfacelocale

How to refresh all UIs on locale update for an Android app without restarting the app?


I need my app to have all UIs refreshed to use the new locale that the user just switches to without the need of restarting the app, is there a way to do it?

When I tested my app, for example, I was using English and now I change to use French, some UIs did get updated to display in French while some remains in English. Is there anything I could have been missing?

Thanks!


Solution

  • If locale is changed via device settings, then default behavior for activities is they are recreated/restarted by the system automatically, giving them a chance to use proper string resources (if an app has different string resouces for different locales, of course).

    This is called Сonfiguration changes. Other types of config change would be device rotation, font size change, etc. But programmers can override the default behavior iether stating in AndroidManifest.xml what confic changes to bypass OR overriding Activity.onConfigurationChanged().

    So, make sure (1) you have a dedicated string resources for each supported by your app locale and (2) you don't prevent the default on config change behaviour for this type of config change.