in this tutorial : http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-building-application-preference-screens/
they talk about the preference state, and the following method checks wether to set the alarm or cancel it, depending on the boolean in getBackgroundUpdateFlag :
protected void onPause() {
super.onPause();
Context context = getApplicationContext();
if (TutListSharedPrefs.getBackgroundUpdateFlag(getApplicationContext())) {
setRecurringAlarm(context);
} else {
cancelRecurringAlarm(context);
}
}
So there is another method that should “set” the pref called setBackgroundUpdateFlag , but they say :
Although we’ve added a setBackgroundUpdateFlag() method for completeness, we will not be using this method. Read on to see why.
So how can we know when the checkBox Preference is checked, so that the pref state is set to “true”, if we don’t use the set method? is there something done automatically with the Preference CheckBox item from the XML ?
I don’t understand how the pref is updated. ?
Thanks for your help
Yes, preferences state is persisted automatically. You can read that state and you can also add a listener to have your method called back when a preference changes state.
Take a look at the directory /data/data/..your_app../ on your phone, you will see an XML with the saved preferences. (don’t know if it can be viewed on non rooted phones).