Learn Android handler together

In Android development, there are two threads: the main thread (UI thread) and the working thread (worker thread). The two threads are independent of each other and cannot access each other (the main thread is mainly responsible for UI update and cannot carry out time-consuming operations, while the working thread is mainly responsible for time-consuming operations but cannot carry out UI update). Therefore, data transfer should be carried out between the two threads, You need a handler as a bridge to transfer data. Each handler object is related to an independent thread and the message queue of the thread. This article is for learning and sharing only.

As shown in the figure below:

Create an inner class to inherit handler

Create an internal class to inherit thread

Start thread

Debug output information (two different threads)

In most cases, it is not possible to modify the view in the worker thread, and a small part is possible, such as the progressbar.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>