android.os.Handler

Handler

Known Direct Subclasses
1).AsyncQueryHandler                A helper class to help make handling asynchronous ContentResolver queries easier. 
2).AsyncQueryHandler.WorkerHandler
3).HttpAuthHandler                  HTTP authentication request that must be handled by the user interface. 
4).SslErrorHandler                  SslErrorHandler: class responsible for handling SSL errors. 

Class Overview

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允许你发送并处理与线程的MessageQueue相关的Message对象和Runnable对象.每一个Handler实例关联单一的线程及该线程 的消息队列(message queue).当你创建一个新的Handler时,它会绑定线程/以及创建该Handler的消息队列(message queue).从此刻开始,它会发送消息和runnables给消息队列,当它们出消息队列时执行它们.

There are two main uses for a Handler: 
Handler有两种用法:
(1) to schedule messages and runnables to be executed as some point in the future;
(1). 调度messages和runnables以便在将来的某一时刻执行.
(2) to enqueue an action to be performed on a different thread than your own.
(2). 将某一个action入队到一个不同的线程中执行.

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; the sendMessage versions allow you to enqueue a Message object containing a bundle of data that will be processed by the Handler's handleMessage(Message) method (requiring that you implement a subclass of Handler).
可以使用post(Runnable), postAtTime(Runnable, long), postDelayed(Runnable, long), sendEmptyMessage(int), sendMessage(Message), sendMessageAtTime(Message, long), 和sendMessageDelayed(Message, long)方法来完成调度消息. post方法允许Runnable对象入队以便当消息队列接收到它时执行它. sendMessage方法允许q包含数据的bundleMessage对象入队以便handleMessage(Message)方法(这个方法需要你实现一个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.
当post或send给Handler,你可以允许一旦消息队列准备好就可以让每一项都被立刻执行,也可以允许有延迟,也可以在某一确切的时刻执行.后两者允许你实例timeouts,ticks及其它基于时间的行为.

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.
当应用程序创建process时,它的主线程专注于执行关注于上级应用对象(activities, broadcast receivers等)的消息队列及它们创建的windows.你可以创建你自己的线程,并通过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.

详情请见:http://developer.android.com/reference/android/os/Handler.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值