Reputation: 61
I have a service that is running in the background. In my application when X happens, I need to tell the service to do something. Is it better to bind to that service or send out a broadcast that the service would receive in order to get the service to perform the proper action?
Thanks
Upvotes: 6
Views: 909
Reputation: 64700
Bind is more efficient, I'd generally recommend it.
The broadcast is more loosely coupled and so might be easier to code up though: you just broadcast the Intent in the Activity and don't require any more thought, and in the Service you don't have to do any work dealing with binders, just register a receiver in your onCreate()
and unregister it in onDestroy()
. You don't actually have to track anything about the Service.
Upvotes: 4