Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bind to service vs Intent base communication

I have found that it is possible to communicate with services by use of either Intents or direct binding . Why should direct binding could be useful ? and isn't it a bad practice that sounds like high coupling with components ?

like image 203
user2489696 Avatar asked Sep 08 '13 08:09

user2489696


People also ask

What is the difference between service and intent Service?

Service will always run on the main thread. intent service always runs on the worker thread triggered from the main thread. There is a chance of blocking the main thread. tasks will be performed on a queue basis i.e, first come first serve basis.

What is binding a service?

The basics. A bound service is an implementation of the Service class that allows other applications to bind to it and interact with it. To provide binding for a service, you must implement the onBind() callback method.

What is the difference between bound and unbound service in Android?

The Unbound service runs in the background indefinitely. Where As The Bound service does not run in the background indefinitely. The Unbound service is stopped by stopService() method. Where As In The Bound service, The client can unbind the service by calling the unbindService() method.

What are the components you can bind to a service?

Application components (clients) can bind to a service by calling bindService() . The Android system then calls the service's onBind() method, which returns an IBinder for interacting with the service. The binding is asynchronous. bindService() returns immediately and does not return the IBinder to the client.


1 Answers

Usually a service which is started with context.StartService() with intents performs a single operation and does not return a result to the caller.and this service can run indefinitely and the service should stop itself by calling stopSelf().

Where as bounded service offers a client server interface that allows components to interact with the service and send requests,get results and even do so across processes with inter process communication(IPC).One or more component can bound to this service.this service run only till at least a component is binded to it else it is destroyed(stopd).

want to know more on bounded and unbounded services. Please refer the below link

Bounded and unbounded services

like image 106
khubaib Avatar answered Sep 28 '22 04:09

khubaib