Android: Differences Between Bound and Running Services
I'm trying to figure out the basic conceptual (non-implementation) differences between a linked and started service. Here are the highlights:
- A linked service provides extended two-way communication between an activity and a service, whereas a running service should not return any results to the client activity.
-
A linked service will serve multiple clients (assuming at least one client is bound to it) while a running service performs one operation and then shuts down. (I know there can be services running that are bundled as well)
Are there any other significant differences?
source to share
A service is a component that runs in the background to perform lengthy operations without the need for user interaction. For example, a service can play music in the background while the user is in another application, or it can retrieve data over the network without blocking user interaction with the activity. A service can essentially assume two states:
Begins . A service is started when an application component such as an activity starts it by calling startService (). Once started, the service can run in the background indefinitely, even if the component that started it is destroyed.
Related: A service is bound when an application component binds to it by calling bindService (). A bundled service offers a client-server interface that allows components to interact with the service, send requests, receive results, and even do this through inter-processor communication (IPC) processes.
source to share
The main difference is that the bound service will be terminated by the Android OS when the last client has an unbound, running service, however, does not need any clients and it can run. As you mentioned, you can also make a service that can support interactions with multiple clients, but is not related
The difference also arises when you try to stop them. When you call stopService(..)
on the associated service and it still has a client associated with it, nothing will happen, on the other hand, the running service will stop. When you call unbindService
on a running service nothing happens, and if your service is bound and it is the last client it will be closed ... so all the differences between the two are how they start and eventually end
Also, there is no difference.
source to share