What is the service?
The biggest difference between him and the activity is that he doesn't have a special layout display interface, and he works silently in the background of the app.
Although we do not need to use the service except in a few cases, it is also necessary to understand how the service is used
We know that activity due to its own shortcomings, if the activity has generated a jump, then the current activity will be completely stopped work.
But sometimes we want to continue other activities in the process of listening to the song, calling the phone, downloading the file, and then we should use the service, no matter how the front-end activity changes, as long as the service is not stopped, the service will continue his work.
The workflow flowchart for the service is as follows:
Use the service first to create a new class that inherits from the service
Next we need to register the service in the Androidmanifest.xml file
Let's look at two scenarios for invoking service services:
First, StartService
Second, Bindservice
The biggest difference between the two methods is that Bindservice will automatically unbind the service when the app exits, while StartService needs to terminate the services manually, so we need to choose the appropriate method to invoke
8844302
Android Service First Solution