I’ve read many posts about reloading the Activity. I understand it is not the way to go. However, my PreferenceActivity class loads its view via an xml file. In that xml file all names and descriptions reference the the string.xml file. One of these preference options is to change the language. I use an onPreferenceChangeListener definition to catch and set the new Locale right away. I want behaviour similar to the OS where after you change the language its instantly reflected.
To avoid manually defining each preference option, is there not any way at the end of this method that I can force the xml file to be loaded again and thus all the strings to be grabbed from the new locale?
Thanks for your help, here’s what I have so far, I cut out the locale change to save space:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
Preference langPref = (Preference) findPreference("languagePreference");
langPref.setOnPreferenceChangeListener( new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
/* CHANGE LOCALE */
...
/* FORCE XML TO BE RELOADED */
HOW?
return false;
}
});
}
I’m not saying this is a good answer but to possibly help others, I’ve been able to make a temporary solution to what I want:
I’ve put my change listener creation inside a method called setupListener.
The state of the preference isn’t switching properly for me yet but I’m going to live with it for now.
Updated full code:
Warning: some of the methods are deprecated now. Will have to look into possible changes myself.