Android Handler
来源:互联网 发布:淘宝有多少买家注册 编辑:程序博客网 时间:2024/05/12 22:43
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.
There are two main uses for a Handler: (1) to schedule messages and runnables to be executed as some point in the future; and (2) to enqueue an action to be performed on a different thread than your own.
Scheduling messages is accomplished with the post(Runnable)
, postAtTime(Runnable, long)
, postDelayed(Runnable, long)
,sendEmptyMessage(int)
, sendMessage(Message)
, sendMessageAtTime(Message, long)
, and sendMessageDelayed(Message, long)
methods. The post versions allow you to enqueue Runnable objects to be called by the message queue when they are received; thesendMessage versions allow you to enqueue a Message
object containing a bundle of data that will be processed by the Handler'shandleMessage(Message)
method (requiring that you implement a subclass of Handler).
When posting or sending to a Handler, you can either allow the item to be processed as soon as the message queue is ready to do so, or specify a delay before it gets processed or absolute time for it to be processed. The latter two allow you to implement timeouts, ticks, and other timing-based behavior.
When a process is created for your application, its main thread is dedicated to running a message queue that takes care of managing the top-level application objects (activities, broadcast receivers, etc) and any windows they create. You can create your own threads, and communicate back with the main application thread through a Handler. This is done by calling the same post or sendMessage methods as before, but from your new thread. The given Runnable or Message will then be scheduled in the Handler's message queue and processed when appropriate.
所以Handler的主要应用是你可以在你创建的线程中发送Message出来,这样就可以在主线程的Handler实例中接收到然后进行处理。
- android Handler
- android Handler
- android Handler
- android Handler
- Android Handler
- android---handler
- android-handler
- Android Handler
- Android Handler
- Android Handler
- android Handler
- android--Handler
- Android Handler
- Android Handler
- Android Handler
- Android Handler
- Android handler
- Android Handler
- git的说明和使用笔记
- 交锋线下
- Loadrunner的loadgenerator在linux上的配置和部署 – 使用非RSH连接
- 自定义Dialog设置大小
- 13周项目二(多重继承派生出新类)
- Android Handler
- AIX或UNIX下安装loadrunner的load generator负载生成器组件
- javaBean入门(二)获得表单数据
- dojo模板字符串最佳实践
- Android布局
- Android Fragment的使用(1)
- Web开发者不容错过的20段CSS代码
- LoadRunner的Loadgenerator在unix(linux)下的安装及运行。
- mysql修改表默认字符集可能带来的隐患