1

We have a bit of code in the Application object onCreate method that changes the default local in the configuration of the ApplicationContext.

it looks something like:

Locale locale = new Locale(sSavedLocale);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getResources().updateConfiguration(config, getResources().getDisplayMetrics());

Than we start our main activity and from there our other activities and tasks. As long as i don't cause configuration change like screen rotation everything is ok. if i rotate the screen the Locale returns to the device default, even though the application object remains the same.

Digging into android srouce code of ActivityThread and other inner classes i could see the the ApplicationContext itself and the context in the mainThread is changed back to default on configuration change event.

It seems like a bug to me since i i set the configuration in the application level at app start i probably want to maintain the change unless Local configuration change occurred, and even then....

I didn't check for open bugs i do think of applying one. Anyone thinks i'm wrong and this is ok behavior ?

codeScriber
  • 4,582
  • 7
  • 38
  • 62

1 Answers1

5

You can add onConfigurationChanged to your Application class.

    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
        if (newConfig.locale != null)
        {
            Locale locale = new Locale(sSavedLocale);
            Locale.setDefault(locale);
            Configuration config = new Configuration();
            config.locale = locale;
            getResources().updateConfiguration(config, getResources().getDisplayMetrics());
        }
    }
auselen
  • 27,577
  • 7
  • 73
  • 114
  • interesting, i'll check and get back to u! 10x! I still think it's a bug that i change the Configuration of the current context and it doesn't get saved, onConfigurationChanged will be called, as far as i know in any case, so maybe u are right and that's the place to perform the change. – codeScriber Dec 25 '12 at 16:44
  • that method works, i have no idea why, probably application gets the change before the activity so i can centralize the change in one place, it doesn't matter, it works well :-) – codeScriber Dec 30 '12 at 15:17