The Android service has been running:
A recent project requirement is to run the service in the background all the time, but it can be stopped manually, and here is a way to get the Android service running.
1. Set-> application-> run-> stop-> Kill service
This will restart the service in the OnDestroy () method of the service
public void OnDestroy () {
Intent service = new Intent (this, myservice.class);
StartService (service);
Super.ondestroy ();
}
This method is simple and rough, and the test is effective.
You can also use two service,a and B.
Broadcasts that are sent when the service B is killed in service A, and then restarts service B; Similarly, broadcast B in service B that listens for service a being killed, and then restarts a.
The code written like this is more robust.
2. Set-> application-> downloaded-> stopped running
This forced to stop running, the service does not go OnDestroy () method, so can not be guaranteed to live.
Thank you for reading, I hope to help you, thank you for your support for this site!