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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With