我想获得复选框首选项的值。哪种方法适合听偏好?
OnPreferenceChangeListener 和 OnSharedPreferenceChangeListener 之间的真正区别是什么?!
更新 为什么不调用 onSharedPreferenceChanged?
public class Setting extends PreferenceActivity implements
OnSharedPreferenceChangeListener // ,OnPreferenceChangeListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);// deprecated warning
}
@Override
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String key) {// DO Stuff
}
@Override
protected void onResume() {
super.onResume();
// getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
// PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
this.getSharedPreferences("myPrefDB", MODE_PRIVATE)
.registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void onPause() {
super.onPause();
// getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
// PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
this.getSharedPreferences("myPrefDB", MODE_PRIVATE)
.unregisterOnSharedPreferenceChangeListener(this);
}
}