On Sun, Jul 4, 2010 at 4:57 AM, Federico Paolinelli <[email protected]> wrote: > I am in need of checking the consistency between a couple of values of > default shared preferences, while using the default preference > activity. > > An example is a send mail option which needs a target mail address to > be valid.
Do you mean that you have one preference that is "send mail" and another that is the target mail address? > What I am going to implement is a OnSharedPreferenceChangeListener in > the preferences activity (the one that calls the > addPreferencesFromResource() method, and if some check fails, push > back the change and notify the user with a dialog. > > Now my question is: is there a smarter way to implement these checks? > Do you have any suggestions? If these are both preferences, you can use android:dependency to set up a relationship between them: http://developer.android.com/reference/android/preference/Preference.html#attr_android:dependency I have not tried this, so I do not know its possible limitations. > And more: will the onSharedPreferenceChanged be called only if the > activity which registers it is visible? I think it will be called regardless of whether the activity is visible or not, but I am not certain. Certainly, services can register such listeners, and they are notified all of the time, since there is no concept of a service being visible or not. > Just to be sure I will > unregister the listener in onPause(). That sounds like a good idea. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Consulting: http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

