Detailed explanation and implementation of Android service service will not be stopped
Android service always running:
Recently, there is a project requirement that the service is always running in the background, but it can generally be stopped manually. Here is a method to make the Android service run all the time. Let's have a look.
1. Setting - > Application - > running - > stop - > kill service
In this way, you can restart the service in the ondestroy () method of the service
This method is simple and effective
You can also use two services, a and B
Listen to the broadcast sent when service B is killed in service a, and then restart service B; Similarly, listen to broadcast B sent when service a is killed in service B, and then restart a
The code written in this way is more robust
2. Setting - > Application - > downloaded - > stop operation
In this way, the service is forced to stop running, and the ondestroy () method will not be used, so it cannot be kept alive
Thank you for reading, hope to help you, thank you for your support to this site!