Android service services are not stopped and implemented _android

Source: Internet
Author: User

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!

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.