Android self-use-service-related

Source: Internet
Author: User

 

1. A service is a reliable component with unbounded boundaries. Reliability means that a service is generally not shut down when it is started, even if the application process of the service is killed, it also runs continuously, unless the memory resources are insufficient, shut down unexpectedly, or the code is used to close it. The intent sent from the outside is repeatedly executed by the service to ensure the service quality.

2. When a service is enabled and the service is enabled again, a new instance object of the service is not generated, but a new instruction is sent to the original service instance, execute the onstartcommand () method in the service. Therefore, it is best to write the operation code of our own application in this method. If it is written in onstart (), it may not be executed.

3. There are two methods for starting a service: startservice () and onbind () method to start the service (send new commands ).

Startservice and bindservice can both start the service. What is the difference between them? The difference between them is to change the service cycle. The service started by startservice must have stopservice to end the service. If you do not call stopservice, the activity ends and the service is still running. The service started by bindservice can be ended by unbindservice, or automatically ends after the activity ends (ondestroy.

 

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.