On 4 Lug, 11:24, Mark Murphy <mmur...@commonsware.com> wrote:
> On Sun, Jul 4, 2010 at 4:57 AM, Federico Paolinelli <fedep...@gmail.com> 
> 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?
>

Yes, and if the user checks the send mail preference I want to be sure
there is a valid address to send the mail to, plus, for example, check
with a regex that he put a formally valid email address instead of a
random string

> > 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....
>
> I have not tried this, so I do not know its possible limitations.
>

I'll give a look, but checking from the code sounds easier to me

> > 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.
>

Good point. However if the goal is just to check the user input during
the preferences activity, makes sense not to have the listener
registered if the activity is in background, plus I have no idea of
what would happen if a background activity tries to show a dialog.

> > Just to be sure I will
> > unregister the listener in onPause().
>
> That sounds like a good idea.
>


Thanks again, fast and straightforward as always.

   Federico

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to