<span id="Label3"></p><p><p>Android asynchronous message processing consists of four main parts: Handler,looper,message,messagequeue</p></p> <p><p>Message: messages passed between threads that can carry a small number of messages inside</p></p> <p><p>MessageQueue:</p></p> <p><p>Looper: each thread has and can have at most one Looper object, which is a threadlocal (thread-local storage object);</p></p> <p><p>(ThreadLocal: implements a thread-local storage object, for a variable, each thread has its own value, and all threads share the same object, but variable changes in one thread do not affect the value of that variable in the other Thread)</p></p> <pre class="brush:java;toolbar: true; auto-links: false;"><pre class="brush:java;toolbar: true; auto-links: false;">/** * Implements a thread-local storage, that's, a variable for which each thread * have its own value. All threads share the same {@code ThreadLocal} object, * But each sees a different value when accessing it, and changes Ma De by one * thread does not affect the other THREADS. The implementation supports * {@code null} values. * * @see Java.lang.Thread * @author Bob Lee * *</pre></pre> <p><p>Looper internally maintains a Mq,loop () method call after the thread starts to continuously remove the message from the queue execution</p></p> <p><p>handler:1. for processing and sending messages;</p></p> <p><p>2. Associate an MQ in Looper and looper at Creation time;</p></p> <p><p>3. A thread can have multiple handler;</p></p> <p><p>4.Handler can send messages on any thread, and messages are added to the associated mq;</p></p> <p><p>5.Handler is the processing of messages in its associated looper thread.</p></p> <p><p><br></p></p><p><p>Android asynchronous message processing mechanism</p></p></span>
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