Handler
| java.lang.Object | |
| ↳ | android.os.Handler |
| Known Direct Subclasses |
原意:
A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.
译文:
一个Handler允许你去发送并且处理信息而且Runnable接口对象是和我们的一个线程MessageQueue相联系的。每个Handler实例与单个线程,该线程的消息队列相关联的。当您创建一个新的Handler,它是绑定到线程/消息的线程产生了这个队列 -从这点上来看,它会提供信息,并到该消息队列的Runnable并执行他们,因为他们来的消息出来队列。
Handler的主要作用:
Handler主要是用来跟UI主线程交互用。 比如: 1、你用handler发送一个message,然后在handler的线程中来接收、处理该消息,以避免直接在UI主线程中处理事务导致影响UI主线程的其他处理工作。 2、你可以将handler对象传给其他进程,以便在其他进程中通过handler给你发送事件。 3、通过handler的延时发送message,可以延时处理一些事务的处理
理解Android应用中的Handler机制
本文深入探讨了Android应用中Handler的作用与实现机制,包括如何使用Handler进行线程间通信,以及其在UI线程交互中的重要性。此外,文章还介绍了Handler的主要作用和常见应用场景,如发送和接收消息、在不同进程间传递事件等。
577

被折叠的 条评论
为什么被折叠?



