Summary
If you have never touched the service before, you can have a general understanding of the following content. After using the service, read this chapter to learn more deeply.
Service is one of the four Android components, and the rest are activity, BroadcastReceiver, and Content Provider. A service is an application component that can perform long-term operations in the background. It does not provide a user interface. Applications can start background operations through services, and different applications can also implement inter-process communication (IPC) through services ).
After a service is started, it actually runs in the main thread, that is, the UI thread. If you want to perform time-consuming operations, it is recommended to create a new thread for processing; otherwise, the UI thread can be blocked, affecting the user experience.
1. service types and differences
There are four types of android Services described here, which are described below.
1.1 Started Service
That is, the started Service. It is one of the two common services, and the other is the Bound Service. It is often used to execute a background operation of a process, such as file downloading through this service.
To provide the started Service: first, create a class that inherits from the Service. Other applications can then start the service through startService (). To stop the service, you can execute stopService () in the application or stopSelf () in the service () to stop the service.
Once a service is started, it can run on the background indefinitely even if its components are destroyed. Generally, a started Service performs a single operation and does not return results to the caller. To return results, you can use BroadcastReceiver. These are described in detail in "Android Service -- Started Service.
1.2Bound Service
That is, the bound Service, like Started Service, is also one of the two common services. It is also often used to execute a background operation of a process, such as using this service to download files and other functions.
To provide the Bound Service: first, create a class that inherits from the Service. Then, other applications can bind the service through bindService (). After the service is bound, the functions provided by the service can be called. To remove the service, you can run unbindService () in the application ().
The main differences between "Started Service" and "Bound Service" are as follows:
(01)Different start/stop Methods: