There are pluses and minus to either approach.  Broadcasts are good,
for example, if you are loosely coupled with your clients: you don't
need to know about them, just want to send out new data to anyone who
might be interested, and allow things that aren't even running to
receive those broadcasts.  Callback interfaces are good in situations
where you are more tightly coupled with clients, for example when an
activity comes to the foreground it wants to register with the service
to start receiving information from it, and be able to control what
kind of information is being received, get complex data or
interactions, send data back, etc.

An example of using a callback interface is the Remote Service Binding
example code here:

http://code.google.com/android/samples/ApiDemos/src/com/google/android/samples/app/

(Note that the .aidl files are not currently copied into the docs, so
you'll need to find them in the actual example in the SDK.)

On May 16, 8:16 am, Mark Murphy <[EMAIL PROTECTED]> wrote:
> My wrote:
> > Currently im developing instant messaging library. Right now i created
> > a Service wich open TCP connection to the server. im thinking about
> > creating a java interface which fill with a callback method that will
> > be executed when event happen in the service (such as new message,
> > buddy list, disconnect etc).
> > user using this library can implement this interface from the activity
> > and pass it back to the service so the activity can handle the event.
>
> Off the cuff, I would recommend the service use broadcastIntent() and
> your activity receive those intents.
>
> This provides flexibility:
>
> -- Your service might support not only your activity, but an activity
> some other developer creates, effectively reusing your service's
> capabilities
>
> -- Your activity might be able to support IM capabilities provided by
> multiple services, if those services commit to a consistent set of
> Intents for different events
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com
> The Busy Coder's Guide to Android Development -- coming in June 2008!
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to