There are many ways on the internet
Method One: Fork out the sub-process in JNI
Service in a separate process, invoke the JNI code in the service, then fork out a process, and then let our service process and the forked child process run all the time.
Under 5 is possible, above 5 invalid,
Code for 5.0:
Process.killprocessquiet (APP.PID);
Process.killprocessgroup (App.info.uid, app.pid);
code for 4.3:
Process.killprocessquiet (PID);
http://www.aichengxu.com/view/2402010
Method Two: Use push
Integrate the Xiaomi/AU/jpush/homing pigeon push in the app and listen to the daemon in the push service.
So, the right push scheme should be the case (not the system push, the app kills are not up)
1. Third-party push solution + Xiaomi push + Huawei push (two systems push to wake up normal push)
2. If you are supporting foreign applications, remember to put, GCM also added
Method Three: Start_sticky
In Android, we use StartService to start the service. In the service's derived class, Onstartcommand (Intent,int,int) is called to start the services.
There are three types of return values for Onstartcommand:
Start_sticky:
With this return value, the service we start is "stuck" with the application, and the service is automatically restarted if the service is killed unexpectedly after Onstartcommand is executed. When the service is started again, the first parameter passed in will be null;
Start_not_sticky: When using this return value, the system does not automatically restart the service if the service is killed unexpectedly after Onstartcommand is executed.
Start_redeliver_intent: Retransmission INTENT. With this return value, if the service is killed by an exception after Onstartcommand is executed, the service is automatically restarted and the value of intent is passed in.
Method Four: Startforeground
Background running services, by a variety of mobile phone guard and memory cleanup tool to clean up or onlowmemory when it was forcibly killed, there may be a system to reclaim memory mechanism, to avoid this situation can be startforeground to let the service foreground run, When StopService is removed by Stopforeground.
Method Five: 1 pixels at the front desk
The black technology of QQ
But it seems that the above methods of millet mobile phones are not ... If you use push, a broken net will be ruined ...
[android]android service background anti-kill