We always don't want our Android service to be cleaned up by the system, and the most common way to do this is to fork out the child process in JNI and then monitor the service process status. Restart the system by killing it. I tested the android4.3 and android5.0 on the lbe clean memory function, to see if it will not be cleaned up, and found that there are some differences in these two versions of the first to say our code, Our service is in a separate process, invoking JNI code in the service, then fork out a process, and then let our service process and the fork come out of the child process to run. Look at the state after the cleanup.
- android4.4 above, the JNI fork process has not been killed and can restart the service process that was killed.
- android5.0 is it still working? After cleaning up the memory operation, you can see that the fork-out process will also be killed. It seems that this method has been invalidated.
Why 5.0 is not up, let's take a look at Activitymanagerservice,lbe's cleanup memory should call the killbackgroundprocesses to see what difference they have 5.0 of the code
Process.killProcessQuiet(app.pid); Process.killProcessGroup(app.info.uid, app.pid);
4.3 of the Code
Process.killProcessQuiet(pid);
The code for 5.0 adds Killprocessgroup. It seems that the fork process way to let Android service resident memory in the way of 5.0 no use ...
A little reflection on the resident memory of Android service