I'm new to Android development. In my app, when a user changes a preference, a function should be called to update some variables.
This is my current code:
mypref.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference arg0, Object arg1) {
if(arg1.toString().matches("...") == false) {
...
return false;
}
...
updateVariables();
return true;
}
});
The problem is that when updateVariables()
is called, the preference value is not yet updated and the function sees the old value.
private void updateVariables()
{
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
Map<String, ?> savedKeys = sharedPref.getAll();
for (Map.Entry<String, ?> entry : savedKeys.entrySet()) {
// for each preference...
}
}
What would the least invasive solution be? Thanks!