Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind or Broadcast?

Tags:

android

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

like image 744
Nick Avatar asked Apr 29 '11 18:04

Nick


1 Answers

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.

like image 176
Femi Avatar answered Nov 07 '22 02:11

Femi