The main purpose of a Service is to provide backend service calls. Unlike an Activity, a Service has no interface. Because of this, it does not stop when a user leaves the application interface as an Activity, the Service is always running in the background unless the command is explicitly stopped.
Service also has a lifecycle. When the Service is started, the OnCreate () method is called first, and then the onStart () method is called. When the Service is stopped, the onDestroy () method is called.
You can call startService () or bindService () to start a Service (). When the former is used, the system will call the onCreate () method and onStart () method of the Service before the Service is started, and the Service does not stop after use, unless you explicitly stop using stopService. BindService () is used to bind a Service. If the Service does not exist, the binding fails. However, you can set the bindService () parameter to enable the Service when the Service does not exist, after a Service is started using this method, the system automatically stops the Service.
If you only provide background services, you can use Thread threads without using services. Service also features inter-process Service calls, which can be called not only within an application, but also across applications. The program that calls the Service becomes the Client.
To prevent Client threads from being suspended, generally, when a Service is created, a Thread is re-created to complete the specific work. The Service only provides a called interface. If the Client is in another program, the Client and Service run in different processes.
From Yanyun's column