Handler类介绍(中文文档)

Handler类介绍(中文文档)

大家好,又见面了,我是全栈君。

void

dispatchMessage(Message msg)

Handle system messages here.

这里处理系统的消息。

final void

dump(Printer pw, String prefix)

final Looper

getLooper()

String

getMessageName(Message message)

Returns a string representing the name of the specified message. The default implementation will either return the class name of the message callback if any, or the hexadecimal representation of the message “what” field.

返回一个代表指定消息名字的字符串。它的默认实现将返回这个回调消息的类名,或者这个消息“what”字段的十六进制的代表。

void

handleMessage(Message msg)

Subclasses must implement this to receive messages.

子类必须实现它用来接收消息。

final boolean

hasMessages(int what, Object object)

Check if there are any pending posts of messages with code ‘what’ and whose obj is ‘object’ in the message queue.

检查是否有任何即将post带代码“what”和它的obj 是“object”的消息在消息队列。

final boolean

hasMessages(int what)

Check if there are any pending posts of messages with code ‘what’ in the message queue.

检查是否有任何即将post带代码“what”的消息在消息队列。

final Message

obtainMessage(int what, int arg1, int arg2)

Same as obtainMessage(), except that it also sets the what, arg1 and arg2 members of the returned Message.

与obtainMessage()方法一样,除此之外它也能设置what,arg1和arg2返回消息的成员。

final Message

obtainMessage()

Returns a new Message from the global message pool. More efficient than creating and allocating new instances. The retrieved message has its handler set to this instance (Message.target == this). If you don’t want that facility, just call Message.obtain() instead.

从全局消息池中返回一个新的消息。比创建和分配新的实例有效率。这个的重新取回的消息有它的handler设置到这个实例。如果你不想要那套设施,可以通过调用的Message.obtain() 方法替代。

final Message

obtainMessage(int what, int arg1, int arg2, Object obj)

Same as obtainMessage(), except that it also sets the what, obj, arg1,and arg2 values on the returned Message.

与obtainMessage()方法一样,除此之外它也能设置what,obj,arg1和arg2返回消息值。

final Message

obtainMessage(int what)

Same as obtainMessage(), except that it also sets the what member of the returned Message.

与obtainMessage()方法一样,除此之外它也能设置what返回消息成员。

final Message

obtainMessage(int what, Object obj)

Same as obtainMessage(), except that it also sets the what and obj members of the returned Message.

与obtainMessage()方法一样,除此之外它也能设置obj返回消息成员。

final boolean

post(Runnable r)

Causes the Runnable r to be added to the message queue.

使Runnable r添加到消息队列。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。

final boolean

postAtFrontOfQueue(Runnable r)

Posts a message to an object that implements Runnable.

发布一个消息到一个实现了Runnable的对象。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。

final boolean

postAtTime(Runnable r, Object token, long uptimeMillis)

Causes the Runnable r to be added to the message queue, to be run at a specific time given by uptimeMillis.

使Runnable r添加到消息队列中,运行在一个uptimeMillis给出的特定时间。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed — if the looper is quit before the delivery time of the message occurs then the message will be dropped.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。注意true的结果并不意味着Runnable将被执行,如果的这个looper在发送消息之前放弃了,这个消息将被放弃。

final boolean

postAtTime(Runnable r, long uptimeMillis)

Causes the Runnable r to be added to the message queue, to be run at a specific time given by uptimeMillis.

使Runnable r添加到消息队列中,运行在一个uptimeMillis给出的特定时间。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed — if the looper is quit before the delivery time of the message occurs then the message will be dropped.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。注意true的结果并不意味着Runnable将被执行,如果的这个looper在发送消息之前放弃了,这个消息将被放弃。

final boolean

postDelayed(Runnable r, long delayMillis)

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

使Runnable r添加到消息队列,运行在指定时间的流逝之后。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed — if the looper is quit before the delivery time of the message occurs then the message will be dropped.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。注意true的结果并不意味着Runnable将被执行,如果的这个looper在发送消息之前放弃了,这个消息将被放弃。

final void

removeCallbacks(Runnable r)

Remove any pending posts of Runnable r that are in the message queue.

移除任何即将发布的在消息队列里的Runnable r。

final void

removeCallbacks(Runnable r, Object token)

Remove any pending posts of Runnable r with Object token that are in the message queue.

移除任何即将发布的有Object token在消息队列里的Runnable r。

final void

removeCallbacksAndMessages(Object token)

Remove any pending posts of callbacks and sent messages whose obj is token.

移除任何即将发布的回调和发送obj是token的消息。

final void

removeMessages(int what)

Remove any pending posts of messages with code ‘what’ that are in the message queue.

移除任何即将发布的有代码“what”的在消息队列中的消息。

final void

removeMessages(int what, Object object)

Remove any pending posts of messages with code ‘what’ and whose obj is ‘object’ that are in the message queue.

移除任何即将发布的有代码“what”和它的obj是“object”的在消息队列中的消息。

final boolean

sendEmptyMessage(int what)

Sends a Message containing only the what value.

发送一个仅包含what值的消息。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。

final boolean

sendEmptyMessageAtTime(int what, long uptimeMillis)

Sends a Message containing only the what value, to be delivered at a specific time.

发送一个仅包含what值的将在一个特定时间送达的消息。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。

final boolean

sendEmptyMessageDelayed(int what, long delayMillis)

Sends a Message containing only the what value, to be delivered after the specified amount of time elapses.

发送一个仅包含what值的将在特定的时间流逝后送达的消息。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。

final boolean

sendMessage(Message msg)

Pushes a message onto the end of the message queue after all pending messages before the current time.

将一个消息推到当前时间之前的所有挂起的消息之后的消息队列的最后。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。

final boolean

sendMessageAtFrontOfQueue(Message msg)

Enqueue a message at the front of the message queue, to be processed on the next iteration of the message loop. You will receive it in handleMessage(Message), in the thread attached to this handler. This method is only for use in very special circumstances — it can easily starve the message queue, cause ordering problems, or have other unexpected side-effects.

排列一个在消息队列前面的消息,处理下一个message loop的迭代。你将在附属于这个handler的线程里的handleMessage(Message)方法里接收到它。这个方法只能在特殊的情况下使用,它很容易饿死消息队列,引起排序问题,或者还有其他意想不到的副作用。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。

boolean

sendMessageAtTime(Message msg, long uptimeMillis)

Enqueue a message into the message queue after all pending messages before the absolute time (in milliseconds) uptimeMillis. The time-base is uptimeMillis(). You will receive it in handleMessage(Message), in the thread attached to this handler.

排列一个消息进入在绝对时间之前的所有的挂起的消息之后的消息队列。时间坐标是uptimeMillis()。你将在附属于这个handler的线程里的handleMessage(Message)方法里接收到它。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed — if the looper is quit before the delivery time of the message occurs then the message will be dropped.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。注意true的结果并不意味着Runnable将被执行,如果的这个looper在发送消息之前放弃了,这个消息将被放弃。

final boolean

sendMessageDelayed(Message msg, long delayMillis)

Enqueue a message into the message queue after all pending messages before (current time + delayMillis). You will receive it in handleMessage(Message), in the thread attached to this handler

排列一个消息进入在(当前时间+延迟时间)之前的所有的挂起的消息之后的消息队列。你将在附属于这个handler的线程里的handleMessage(Message)方法里接收到它。

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed — if the looper is quit before the delivery time of the message occurs then the message will be dropped.

如果Runnable被成功放置在消息队列中就返回true,如果失败就返回false,常常因为the looper处理消息队列正在退出。注意true的结果并不意味着Runnable将被执行,如果的这个looper在发送消息之前放弃了,这个消息将被放弃。

String

toString()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object’s type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + ‘@’ + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

返回一个包含该对象的简洁的、可读的描述性的字符串。在子类鼓励覆写这个方法,提供一个了解这个对象的类型和数据的实现。默认的实现相当于下面的表达式:

getClass().getName() + ‘@’ + Integer.toHexString(hashCode())

如果你想实现你自己的toString方法,看看写一个有用的toString方法。

转载于:https://www.cnblogs.com/zhaolizhe/p/6924046.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/108459.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • git切换分支上传

    git切换分支上传nbsp nbsp nbsp nbsp 从 master 切换成 dev 分支上传文件 切换分支命令 gitcheckoutd gitclone 克隆特定分支命令 gitclone bdev 地址 传两个图片做个纪念吧 nbsp nbsp nbsp nbsp 看吧 上传成功了 这是一篇 lowlow 的 blog

    2025年12月3日
    3
  • 性能测试平台ngrider

    性能测试平台ngrider一 ngrider 简介 nGrinder 是 NHN 公司基于 Grinder 开发的开源性能测试平台 1 b s 架构 非常易用 有友好简洁的用户界面 能在 Windows linux mac 系统运行 2 具有 controller agent 分布式结构的强大的压力测试工具 能够执行性能测试和监控目标服务器 并保存这些数据生成测试报告 通过动态图和数据表的形式展示出来 3 可以自动生成 jython 和 groovy 语言的脚本 当然 如果想执行一些比较复杂场景的性能测试 测试人员也可以自己编写脚本 导入进来 二 n

    2025年6月6日
    3
  • Windows下如何强制删除文件夹及文件的命令「建议收藏」

    Windows下如何强制删除文件夹及文件的命令「建议收藏」点击Win输入cmd以管理员身份打开输入命令:rd/s/q盘符:\某个文件夹(强制删除文件文件夹和文件夹内所有文件)例如rd/s/qF:\AdobePhotoshop\AdobePhotoshopCS6del/f/s/q盘符:\文件名(强制删除文件,文件名必须加文件后缀名)例如del/f/s/qF:\护眼精灵\huyanjingling.rarhttps://blog.csdn.net/hanhanwanghaha欢迎关注这个超级无敌可爱的人鸭,有什么问

    2022年6月10日
    359
  • 如何在系统中添加字体(添加字体到系统)

    笔者最近在使用win10自带的OneNote笔记本记笔记的时候,发现笔者电脑中没有华文新魏这个字体,最开始以为是OneNote不带有这个字体,经过一段时间的收集资料后发现,是笔者电脑win10系统中不带有这个字体,现将有关概念和字体安装方法做一下记录。字体是win10系统自己带有的,其他的软件自能从win10系统中用调用,而不是说字体是某些软件自带的,比如如果office的PPT中含有华文新魏这个字体,那么OneNote中就必然也含有华文新魏这个字体,并不会存在一个软件有这个字体而另一个软件不含有这个字体

    2022年4月17日
    64
  • ASP.NET使用UpdatePanel实现AJAX

    ScriptManager和UpdatePanel控件联合使用可以实现页面异步局部更新的效果。其中的UpdatePanel就是设置页面中异步局部更新区域,它必须依赖于ScriptManager存在,

    2021年12月21日
    50
  • 安装win10+黑苹果双系统零基础教程

    安装win10+黑苹果双系统零基础教程一、准备工作准备8g以上的U盘安装TransMac安装HasleoEasyUEFI安装DiskGenius系统镜像,格式注意是.dmg,我示范的版本为mac10.13.3二、开始动手首先进行分盘选择磁盘管理将你需要分盘的硬盘压缩新建简单卷,一路操作下去,自己命名磁盘打开DiskGenius,我分机械硬盘了300G给macOS,所有的操作都在刚才新建简单卷中进行调出前部大于3…

    2022年4月30日
    848

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号