美文网首页
Handler&Message初见

Handler&Message初见

作者: ZAdonai | 来源:发表于2018-07-26 12:11 被阅读0次

title: Handler&Message入门

除了AsyncTask之外,Android还提供了其他的线程操作,如Handler、Message、MessageQueue、Looper等模块,这些就是Android的消息处理机制,难

Handler简介

​ 一个Handler会允许你发送和处理Message或者Runnable对象关联到一个线程的消息队列MessageQueue中。每一个Handler实例都会关联到一个单一线程和线程的消息队列。当你创建一个一个新的Handler,它会绑定到你创建的线程和这个线程消息队列中。随后,他就会将Messages和Runnables传递到消息队列,然后当他们出现在消息队列时,执行。

​ 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.


Message简介

Defines a message containing a description and arbitrary data object that can be sent to a Handler. This object contains two extra int fields and an extra object field that allow you to not do allocations in many cases.

我已经见过的用法

Message.obj = ......

An arbitrary object to send to the recipient. When using Messenger to send the message across processes this can only be non-null if it contains a Parcelable of a framework class (not one implemented by the application). For other data transfer use setData(Bundle).

Message.what = 3

User-defined message code so that the recipient can identify what this message is about. Each Handler has its own name-space for message codes, so you do not need to worry about yours conflicting with other handlers.


Message message = new Message();
message.what = 3;
message.obj = socket.getRemoteDevice();
handler.sendMessage(message);

To Be Continued!!!

相关文章

  • Handler&Message初见

    title: Handler&Message入门 除了AsyncTask之外,Android还提供了其他的线程操作...

  • 初见

    初见,曾经的自己 初见,曾经的回忆 初见,曾经的时光 初见,曾经的生活 初见,曾经的书籍 初见,曾经的故人 初见,...

  • Android消息处理机制-Handler&Message概述与

    一、Handle & Message概述 概述:Handler与Message共同构建起了Android的消息处理...

  • 随笔三十|初见

    初见 是前世未完的承诺 初见 是心灵给予的嘱托 初见 是夜夜想念的积淀 初见 是尚未耕耘的心田 初见 是...

  • 停留在三月

    三月是一场初见初见 荒芜中萌发的绿初见 苍凉中乍现的暖初见 柳枝摇曳的柔初见 桃蕊含羞的甜 怎能忘记初见—...

  • 初见

    初见春风,温暖、温柔、浪漫、多情; 初见夏雨,清凉、激情、彩虹、轻狂; 初见秋霜,忧愁、悲戚、沉默、释然; 初见冬...

  • 初见的爱

    初见你, 笑容可掬; 初见你, 清凉爽洁; 初见你, 幽默温暖; 初见你, 我喜欢上了你。

  • 人生若只如初见

    初见美好,初见何求,茫茫人海,与谁相遇都是缘分。 初见那时花开,初见那时花落,初见那时的新奇,一点一滴...

  • 初见

    初见的春是万物复苏 初见的夏是生机勃勃 初见的秋是硕果累累 初见的冬是银装素裹 初见的你是文质彬彬 初见的他是滔滔...

  • 初初见你

    初初见你,后庭花开。 初初见你,春意盎然。 初初见你,抚枝含笑。 初初见你,花开不如你眉眼的笑。 初初见你,温暖的...

网友评论

      本文标题:Handler&Message初见

      本文链接:https://www.haomeiwen.com/subject/cuxbmftx.html