Android: Differences Between Bound And Started Services
Solution 1:
A service is a component that runs in the background to perform long-running operations without needing to interact with the user. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. A service can essentially take two states:
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.
Bound : 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).
Solution 2:
The main difference is that bound service will get terminated by Android OS when the last client has unbound, started service however does not need any clients and it can run. As you already mentioned, you can also make a service that can support multi client communication, but is not bound
Difference also arises when you try to stop them. When you call stopService(..)
on a bound service and it still has a client bound to it, nothing will happen while on the other hand, the started service will get terminated. When you call unbindService
on a started service nothing happens, while if your service bound and this is the last client, it will shut down.... so over all the only difference between them is how they are started and stopped eventually
Apart from that, there is no difference.
Post a Comment for "Android: Differences Between Bound And Started Services"