My app users can change app language from app's setting page so I developed it with Resources.updateConfiguration() and Context.createConfigurationContext() (For deprecating). However almost developer used with Locale.setDefault()
but I don't know why. My app can support multi language without Locale.setDefault()
. I read document, but it seems like too dangerous. Is changing JVM's locale safe for system settings or other app? What is changing JVM locale for? And I think it's enough that using Resource.updateConfiguration()
and Context.createConfigurationContext()
but why developers use Locale.setDefault()
method?

- 608
- 7
- 34
-
What is "too dangerous"? Locale is used first for user interface, and second for formatting numbers, dates, etc. What bad thing do you expect to happen? – H.A.H. Mar 16 '17 at 10:19
-
SetDefault is basically to set the apps language to the device's language, and for that you need to give the app permissions to access which language the device is running on. – Ricardo Mar 16 '17 at 10:23
-
I dont agree with this. She is not asking what will happen if you set the configuration's locale to Locale.getDefault(). She is interested in the concequences of setting the JVM default with Locale.setDefault(Locale). – H.A.H. Mar 16 '17 at 10:40
-
@H.A.H. 'too dangerous' means some problem to user's system settings or other apps. And yes, I worried about changing "JVM default locale". I didn't know that each apps has their new JVM instance before k3b's answer. Thank for your comment too! – Soyeon Kim Mar 17 '17 at 00:24
2 Answers
I assume that "safe" means "does not affect other apps"
As far as I know android starts a new JVM instance for every started apk/app. Hence Locale.setDefault()
should not influence other android apks/apps. So it should be safe.
I have done it here and saw no effects on other apps.
-
Thank for answer. And I found this Android's document (https://developer.android.com/guide/components/fundamentals.html). Attaching for other developer like me. – Soyeon Kim Mar 17 '17 at 00:38
According to Locale.setDefault() documentation. What setDefault() does is that it
Sets the default locale for this instance of the Java Virtual Machine. This does not affect the host locale.
The host locale
here references the Android OS locale. And the Java Virtual Machine (JVM) instance
would translate into an Android Runtime (ART) instance in Android terms, with this information we can deduce that since each Android application process runs its own independent ART instance, it means that setDefault() would only affect that one Android app process, and not the whole OS, or any other app process.

- 969
- 10
- 12