Merge "Fix race condition while changing the system locale"
This commit is contained in:
commit
aaa9e8626a
1 changed files with 7 additions and 5 deletions
|
@ -168,12 +168,14 @@ public class LocaleUtils {
|
||||||
* @param newLocale the locale to change to.
|
* @param newLocale the locale to change to.
|
||||||
* @return the old locale.
|
* @return the old locale.
|
||||||
*/
|
*/
|
||||||
public static Locale setSystemLocale(final Resources res, final Locale newLocale) {
|
public static synchronized Locale setSystemLocale(final Resources res, final Locale newLocale) {
|
||||||
final Configuration conf = res.getConfiguration();
|
final Configuration conf = res.getConfiguration();
|
||||||
final Locale saveLocale = conf.locale;
|
final Locale oldLocale = conf.locale;
|
||||||
conf.locale = newLocale;
|
if (newLocale != null && !newLocale.equals(oldLocale)) {
|
||||||
res.updateConfiguration(conf, res.getDisplayMetrics());
|
conf.locale = newLocale;
|
||||||
return saveLocale;
|
res.updateConfiguration(conf, res.getDisplayMetrics());
|
||||||
|
}
|
||||||
|
return oldLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>();
|
private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>();
|
||||||
|
|
Loading…
Reference in a new issue