I want to rotate my phone and keep the locale. I have folders values, values-en and values-hr. In every activity I have
android:configChanges="keyboardHidden|orientation|locale"
and in every activity.java file I have
private Locale locale = null;
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (locale != null)
{
newConfig.locale = locale;
Locale.setDefault(locale);
getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
}
}
and in onCreate
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
Configuration config = getBaseContext().getResources().getConfiguration();
String lang = settings.getString("language","en");
if (! "".equals(lang) && ! config.locale.getLanguage().equals(lang))
{
locale = new Locale(lang);
Locale.setDefault(locale);
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}
It works till I rotate my phone - app is still working, buttons and everything is fine - but locale is getting weird - sometimes it's my locale (hr) sometimes it's (en)...
What else I need to add?