jacek jacek - 15 days ago 6
Android Question

How to get CheckBoxPreference value within the Receiver/Service in Android?

I use

CheckBoxPreference
in my
PreferenceActivity
to set a value. Later on, I want to check that value from Receiver and/or Service.
findPreference()
method is not available from that context. I know, that this preference value is stored in
SharedPreferences
anyway, but what is the key? How could I get the value of the checkbox?

Answer

I know, that this preference value is stored in SharedPreferences anyway, but what is the key?

Whatever value you have for android:key in your preference XML.

How could I get the value of the checkbox?

Call PreferenceManager.getDefaultSharedPreferences() to get the SharedPreferences, then call getBoolean() with the key you used in android:key.