I want to have a configurable language settings in my app.
So, in onCreate of my activity, I call Resources.updateConfiguration with the new locale.
However, after onCreate (at some time, I can't find it when), the locale is set back to the default locale.
On the code example below, the strings shown in the main layout (as inflated by setContentView) shows the "in" language version, BUT when I press the menu button, on which onCreateMenu is called, the strings is taken from the "en" (default) locale.
The log shows this:
18337 oncreate D { scale=1.0 imsi=525/1 loc=intouch=3 keys=1/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=143}
30430 ActivityManager I Displayed activity yuku.coba.locale/.CobaLocaleActivity: 266 ms (total 266 ms)
18337 KeyCharacterMap W No keyboard for id 65540
18337 KeyCharacterMap W Using default keymap: /system/usr/keychars/qwerty.kcm.bin
18337 onmenu D { scale=1.0 imsi=525/1 loc=en_GB touch=3 keys=1/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=143}
Between "oncreate" and "onmenu", the locale magically changes.
Please help, I have been tinkering with this with no luck.
Code snippet:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Configuration c = new Configuration();
c.locale = new Locale("in");
getResources().updateConfiguration(c, null);
setContentView(R.layout.main);
Log.d("oncreate", getResources().getConfiguration().toString());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.d("onmenu", getResources().getConfiguration().toString());
new MenuInflater(this).inflate(R.menu.utama, menu);
return true;
}