Tutorial :Service binding relation


Can one service be bound to n activities?


Yes it can.

From the documentation at https://developer.android.com/guide/components/fundamentals.html :

Clients establish a connection to the Service object and use that connection to call into the service. The connection is established by calling Context.bindService(), and is closed by calling Context.unbindService(). Multiple clients can bind to the same service.

and from https://developer.android.com/reference/android/app/Service.html#ServiceLifecycle:

A service can be both started and have connections bound to it. In such a case, the system will keep the service running as long as either it is started or there are one or more connections to it with the Context.BIND_AUTO_CREATE flag. Once neither of these situations hold, the service's onDestroy() method is called and the service is effectively terminated. All cleanup (stopping threads, unregistering receivers) should be complete upon returning from onDestroy()

So, a service can have multiple bindings.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »