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