I’m using PreferenceActivity to set some preferences about another BroadcastReciever that i have.
While making the skeleton of the preferences GUI is really simple with XML file, i cant find my hands and legs around how to actually DO something with those preferences. especially:
-
How do i register my
BroadcastRecieverto listen to changes in my preferences?
Its look like that the context of the broadcast reciever is not the same as the activity so i’m not registering to the rightSharedPreferencesbecause i dont intercept those changes. -
How do i act in my
PreferenceActivityupon changes in the preferences? i guess i dont need to registerPreferenceActivityas listener to the preferences, so there must be more simple way. -
How do i change the UI of the
PreferenceActivityappropriate to the changes in the preferences? for example, set the “Summary” attribute of a preference to the value that the user chose? -
How do i enable or disable some preferences that depends on another preference (like
CheckBoxPreference)? so the user could edit those preferences only if he enabled the feature first.
I looked al over the documentation but there is no example of using PreferenceActivity beyond the point of just adding preferences from XML.
I feel like i’m missing something huge here, because it looks so simple, and yet i can’t figure it out…
Please try to answer on any of my question.
BTW:
I’m developing for Android 1.6 so all the new PreferenceFragment can’t be used.
If the
BroadcastReceiveris registered in the manifest, you don’t listen to changes in your preferences, because theBroadcastReceiverwill only be around for milliseconds. Just read the latest values in duringonReceive().If the
BroadcastReceiveris registered by some other component callingregisterReceiver(), that component can register anOnSharedPreferenceChangeListenerwith theSharedPreferencesretrieved viaPreferenceManagerandgetDefaultSharedPreferences().That sentence makes no sense.
Register an
OnSharedPreferenceChangeListenerwith theSharedPreferencesretrieved viaPreferenceManagerandgetDefaultSharedPreferences().Generally, you don’t. You are welcome to register an
OnSharedPreferenceChangeListenerwith theSharedPreferencesretrieved viaPreferenceManagerandgetDefaultSharedPreferences(). From there, you can get thePreferencefrom yourPreferenceActivityviafindPreference()and adjust to suit.Add
android:dependencyto your preference XML as needed.