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