handler.发送消息后,是怎么调用handleMessage方法的?
来源:3-6 Handler实现倒计时并优化内存
Polaris717
2018-11-19 23:35:10


问题1:第一张图 先是创建了一个 handler:CountdownTimeHandler handler = new CountdownTimeHandler(this);
然后发送了 消息:handler.sendMessageDelayed(message,DELAY_MILLIS);
循环发消息控制是在handleMessage里面的,这个方法是怎么调用的?
问题二:图二if循环体里面 :sendMessageDelayed(message, DELAY_MILLIS); 前面为什么不加 handler.
1回答
irista23
2018-11-20
Handler为Android提供了一种异步消息处理机制。
1、handler.sendMessageDelayed(message,DELAY_MILLIS)是延长指定的时间发送消息到消息队列,当从消息队列中读取消息时系统会自动回调Handler中的handleMessage(Message)方法处理该消息。
2、sendMessageDelayed()是handler中定义的方法,所以在一个继承了父类的子类中,去使用定义在父类的public方法,不需要前面加handler。
相似问题