I have a Restore default settingsoption in my PreferenceActivity. After the settings are changed I call onContentChanged(). But for some reason the visual state of my CheckboxPreference is not updated.
The only workaround if found is to update the state manually:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean autoStartValue = prefs.getBoolean("auto_start", true);
CheckBoxPreference autoStartPref = (CheckBoxPreference)findPreference("auto_start");
autoStartPref.setChecked(autoStartValue);
// Notify that the preferences changed
EditPreferencesActivity.this.onContentChanged();
What is the correct way of doing this?
You have to register the
OnSharedPreferenceChangeListener()and update your preference yourself.