Can anybody explain what is difference between unbound and bound service in android

mohan picture mohan · Aug 11, 2014 · Viewed 26.4k times · Source

Can anybody explain what is difference between unbound and bound service in android and explain about intent service

Thanks

Answer

Spurdow picture Spurdow · Aug 11, 2014

Bound Service

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).

When the last client unbinds from the service, the system destroys the service EXCEPT If the service was started by startService

Unbound Service or Started

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.

BUT

Most confusion about the Service class actually revolves around what it is not:

A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.

A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).

That is where IntentService are used.

IntentService is a subclass of Service that uses a worker thread to

handle all start asynchronous requests (expressed as Intents) on demand, one at a time. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.

Example

hope it helps :)