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.