Service Summary of four components

Source: Internet
Author: User

Summarize and improve, with June mutual encouragement!


1. What is the service?

The Service is not visible to the interface, is a non-interface activity, and long-term running in the background of a component.
Because of the limitations of the ANR response time to activity and broadcastreceiver (the activity responds to events for no more than 5 seconds, Broadcastreceiver executes no more than 10 seconds), making it unsuitable for more time-consuming operations like networks, The execution of time-consuming operations such as databases and complex computations requires a component to bear. Service as one of the four components of Android, one of its functions is the execution of time-consuming operations.


2. How to start service

There are two main types, bound and unbound

(1) Start with call Context.startservice () and End with call Context.stopservice ()
(2) Set to call the Context.bindservice () method to call Context.unbindservice () to close

Note:

Call the StartService () method to start the service, and the system will callback the service class's OnCreate () and the OnStart () method. This starts the Service running in the background until the Context.stopservice () or Selfstop () method is called. In addition, if a Service has been started, the other code attempts to call the StartService () method, is not executed onCreate (), but will be re-executed once OnStart () .
Another way to Bindservice () is to tie the service to the client class that invokes the service, and if the call to this client class is destroyed, the service will be destroyed .


3. Service life cycle




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Service Summary of four components

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.