Handler is used for registration.

Source: Internet
Author: User

1. Handler Definition

It mainly receives data sent by sub-threads and uses this data with the main thread to update the UI.

Details:

When an application is started, Android starts a main thread (that is, the UI thread). The main thread is used to manage the UI controls in the application for event distribution. However, if we need

When we need a time-consuming nitrogen oxide, such as reading data online or reading a large local file, we cannot put this operation in the main thread, because if it is placed on the main line

Process, the interface will be suspended, if 5 seconds has not been completed, the program will be closed.

At this time, we need to put these time-consuming operations in the Child thread, because the child thread involves UI updates, while the andorid UI can only be updated in the main thread, and the Child thread operates the UI

It is dangerous. So handler appears.

Since handler runs in the main thread, it and the sub-thread can transmit data through the message object, at this time, handler is used to receive the Sub-thread using sendmessage ()

Place the message in the master thread queue and update the UI with the master thread.

 

Handler is used for registration.

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.