Android service is not killed

Source: Internet
Author: User

1. re-write the following method in service. This method has three return values. start_sticky indicates that the service is automatically overwritten after it is killed.
@ Override
Public int onstartcommand (intent, int flags, int startid ){
Return start_sticky;
}----------------
@ Override
Public int onstartcommand (intent, int flags, int startid ){
// Todo auto-generated method stub
Log. V ("trafficservice", "startcommand ");

Flags = start_sticky;
Return super. onstartcommand (intent, flags, startid );
// Return start_redeliver_intent;
}
2. Restart the service in ondestroy () of the service.
Public void ondestroy (){
Intent localintent = new intent ();
Localintent. setclass (this, myservice. Class); // restart the service upon destruction
This. startservice (localintent );
}---------------------------------------------
When a process is killed by a QQ Butler, the system's built-in mandatory kill function (in settings) is called. During the kill process, the entire process of the application is stopped, of course, if the service is forced to kill in running, the process is still displayed. Neither kill the entire process nor kill the service that falls into the application, nor restart the service. I don't know how you restarted it...
PS: In eclipse, when the stop button is used to kill the process, the service will be restarted.
Kill:
1. Stop Service in settings
In the ondestroy method, call startservice to restart the service.
2. Force Stop Application in settings
Capture System broadcast (action is Android. Intent. Action. package_restarted)
3. Kill the running task with a third-party Application
Improve Service priority

Related Article

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.