Android Learning Note (14) Handler theory supplement

Source: Internet
Author: User
First, how to download Android source code

In SDK Manager, select the sources for Android SDK.

Ii. Preliminary introduction of Threadlocal

1) Executes the set (Object obj) method of the ThreadLocal object (static final ThreadLocal sthreadlocal) and stores a key-value pair with the current thread as the key.

2) Execute the Get () method of the Threadlocal object, and the corresponding value will be fetched according to the current thread object as the key.

In the Looper method call that was mentioned earlier:

When Looper.prepare is executed, the system generates a Looper object, which is then stored (set) with the current thread through threadlocal. When the handler object is generated, the Looper object is taken (get) according to the name of the thread and assigned to the Mlooper member variable of the handler object. So the relationship between Looper and handler is connected by Threadlocal .

Generating a Looper object generates a MessageQueue object corresponding to it. After the handler object is generated, both the Looper object and the MessageQueue object are assigned to the member variables of the looper.

Android Learning Note (14) Handler theory supplement

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.