Demo entry 6265566

a

   

Submitted by quantai.zhu on Oct 16, 2016 at 06:14
Language: Java. Code size: 1.2 kB.

final MessageQueue mQueue;
final Looper mLooper;

//逐层调用,最终调用会到enqueueMessage()
public final boolean sendMessage(Message msg)
{
    return sendMessageDelayed(msg, 0);
}
public final boolean sendMessageDelayed(Message msg, long delayMillis)
{
    ...
    return sendMessageAtTime(msg, SystemClock.uptimeMillis() + delayMillis);
}
public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
    MessageQueue queue = mQueue;
    ...
    return enqueueMessage(queue, msg, uptimeMillis);
}
private boolean enqueueMessage(MessageQueue queue, Message msg, long uptimeMillis) {
    msg.target = this;//将发送Message的Handler设为Message的target
    ...
    return queue.enqueueMessage(msg, uptimeMillis);//使用MessageQueue对象将其添加到队列中
}

//如下的几个方法同理
public final boolean sendEmptyMessage(int what)
{
    return sendEmptyMessageDelayed(what, 0);
}
public final boolean sendEmptyMessageDelayed(int what, long delayMillis) {
    Message msg = Message.obtain();
    msg.what = what;
    return sendMessageDelayed(msg, delayMillis);
}

//移除消息
public final void removeMessages(int what) {
    mQueue.removeMessages(this, what, null);//调用消息队列移除内部指定消息
}

public void handleMessage(Message msg) {//子类重写此方法来自定义处理消息
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).