[android-developers] Re: Use one handler for multiple activties

Your background thread should provide a method that allows the caller to register a listener (and a method to un-register again).
When you background thread has new data to show from the network, it calls the listener(s) with the necessary parameters.

When (one of) your activity is coming to the foreground (onResume()), you call that method on your background thread to register itself as a listener.
This way, it will be called by your background thread when new data comes in.

When your activity is going to the background again (onPause), you un-register it so that callbacks to your activity are no longer occurring.

Be sure to have your background-thread call the listener(s) in the UI-thread (see Handler), since you can only update UI elements in the UI thread.

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en