Long-Running Service Implementation
Now that the
LightedGreenRoom implementation is finished, we are almost ready to present the long-running service abstraction. However, we have to take one more detour to explain the lifetime of a service and how it relates to the implementation of
onStartCommand. This is the method that is ultimately responsible for starting the worker thread and the semantics of a service.
You know that the broadcast receiver invokes the service using a
startService call and that this call will result in calling the
onStartCommand method of the service. The lifetime of the service is controlled by what this method returns.
To understand what happens in this method, you need detailed background on the nature of local services. ...