senzacionale senzacionale - 1 year ago 102
Android Question

when is smart to use bindService and when startService

This may be a stupid question but I would like to know when it is smart to use

and when to use

For example:

If I use
, the service will be started and created automatically as is written here:

When is it smart then to use
and when
? I really don't understand these two correctly.

Answer Source

You usually use bindService() if your calling component(Activity) will need to communicate with the Service that you are starting, through the ServiceConnection. If you do not want to communicate with the Service you can use just startService(). You Can see below diffrence between service and bind service.

From the docs :


A service is "started" when an application component (such as an activity) starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. Usually, a started service performs a single operation and does not return a result to the caller. For example, it might download or upload a file over the network. When the operation is done, the service should stop itself.


A service is "bound" when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed.

You can read more here : Android Services, Bound Services

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download