views:

149

answers:

1

Hello,

I've chosen the path to have each Activity implement a onSharedPreferenceChangedListener. In order for a service to update values to be sent back to several Activities at once (it doesn't care which one has the focus)

When the Listener is called, I only have the key. I then have to perform a lookup of that key to get the corresponding View. This has been unsuccessful. I tried using getCurrentFocus() and then a findViewWithTag(). Even tried a .getRoot() after getFocus().

For testing purposes I just tried getting a handle to the View outside of the Listener. I had to make sure setText ran in a runnalbe inside of the UIthread to work.

I've look at some other code and they perform a bunch of else if checks on the key. I could do this to dynamically get a handle to the view because I'll know what the id that corresponds to the string key it, but both ways seem inefficient.

This brings me to the overall question. Is that a way to populate a View's text directly from a Preference using XML? Then I wouldn't have to worry about the different Activities implementing a Listener. Everything would be contained in the XML file that I can move around freely.

A: 

In order for a service to update values to be sent back to several Activities at once (it doesn't care which one has the focus)

Why not use a broadast Intent, then? Or listener objects registered by the activities with the service?

Is that a way to populate a View's text directly from a Preference using XML?

Not for arbitrary activities.

CommonsWare