[android]android service background anti-kill

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.