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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

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