Android Core Component Service

Source: Internet
Author: User

Service: Services

Service is one of the core components of the activity system. Hence the need to inherit and register

Service is an internal interface, suitable for long-term execution of tasks in the background. (such as singing, detection version with new, download, upload, etc.)

Although the service is suitable for long-running tasks, the service runs on the main thread. So time-consuming operations in the service need to turn on sub-threads to implement

Service life cycle:

1. Turn on the service

OnCreate () The first activation is called

Onstartcommand () will be called every time the activation is activated.

2. Turn off the service

OnDestroy ()

To turn service on and off:

Open:

Intent Intent = new Intent (context, xxxservice.class);

StartService (Intent);

Shut down:

Intent Intent = new Intent (context, xxxservice.class);

StopService (Intent);

Stickiness of Service

When the service component is terminated unexpectedly, it is restarted automatically over a period of time. This feature is called the stickiness of the service.

The stickiness of the Service is determined by the return value of the Onstartcommand () method. The return value can be expressed using a constant,

The values are:

Start_sticky: Sticky

Start_sticky_compatibility: Sticky in compatibility mode

Start_not_sticky: Non-sticky

Start_redeliver_intent: Sticky, and resend the INTENT object used to activate the service

Android Core Component Service

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.