Android Four Components service (6) Sticky and non-sticky

Source: Internet
Author: User

Note that the Onstartcommand () method must return an integer. This integer is a description of how the system should continue to run after the service is killed (

The default Intentservice implementation code in the previous section will handle this for you, and you will not be able to modify this process, of course.

The return value of Onstartcommand () must be one of the following constants:

Start_not_sticky
if the system kills the service after Onstartcommand () is returned, the service will not be rebuilt unless there is an unsent intent.
This is the safest option to avoid service runs when the service is no longer required and the application can simply restart those unfinished work.
Start_sticky
if the system kills the service after Onstartcommand () returns, it rebuilds the service and calls Onstartcommand ().
instead of feeding the previous intent again, the Onstartcommand () is called with a null intent. These remaining intent will continue to be sent, unless there are intent that have started the service
. This applies to media players (or similar services), which do not execute commands, but need to be running and ready to stand by.
Start_redeliver_intent
if the system kills the service after Onstartcommand () returns, it rebuilds the service and calls Onstartcommand () with the last intent that was sent.
Any intent that have not been sent will be fed in turn. This applies to active services that require immediate recovery, such as downloading files.

Android Four Components service (6) Sticky and non-sticky

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.