Android Service with Intentservice

Source: Internet
Author: User

Intentservice: Asynchronous Processing Service, opening a new thread : Handlerthread a message in the thread, and then accepts that processing completes, cleans up the threads, and shuts down the service.

Intentservice has the following features:

(1) It creates a separate worker thread to handle all the intents that pass through Onstartcommand () to the service.

(2) Create a task queue to send intent to onhandleintent ().

  Each request is processed in a separate worker thread and does not block the application's main thread

(3) Do not need to call STOPSELFT () actively to end the service. Because, after all intent are processed, the system automatically shuts down the service.

(4) The default implementation of Onbind () returns null

(5) The purpose of the default implementation of Onstartcommand () is to insert intent into the work queue

Classes that inherit Intentservice must implement at least two functions: constructors and Onhandleintent () functions . To overwrite other functions of intentservice, be careful to call the corresponding function of the parent class through Super.

Onhandleintent () Method:

Intentservice in the execution of the OnCreate method, actually opened a thread handlerthread, and obtained the current thread queue management Looper, and in the OnStart, when the message was placed in the message queue

When the message is handler accepted and callback, the Onhandlerintent method is executed, and the implementation of the method is subclass.

Intentservice implements a multi-threaded operation by handler Looper message, while time-consuming operations can be managed and executed by this thread without the case of ANR.

Android Service with Intentservice

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.