在学习handler的过程中,发现handler的一个方法sendMessgeAtTime(Message, long),看了SDK的说明发现看的不是很懂,然后自己调用了一下这个函数,发现设置第二个参数不同的值的时候,有时候能很快接受到消息,有时候等了好长时间还没有接收到,不知道这个函数是干嘛用的,用在什么地方,知道的给我说一下啊

解决方案 »

  1.   

    函数原型:public boolean sendMessageAtTime (Message msg, long uptimeMillis)Since: API Level 1
    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.
    ParametersuptimeMillis The absolute time at which the message should be delivered, using the uptimeMillis() time-base.参数
    Message  //不用说 是待发送消息
    uptimeMillis   //sendMessageAtTime,即在确定的时间发送这个消息,这个时间通过这个参数指定
    这个时间由uptimeMillis()传递
      

  2.   

    回楼主,这两句是等效的,都是延时1秒将消息加入列队
    msgHandle.sendMessageAtTime(msg, SystemClock.uptimeMillis()+1000);
    msgHandle.sendMessageDelayed(msg, 1000)sendMessageAtTime的uptimeMillis是相对系统开机时间的绝对时间,SystemClock.uptimeMillis()是当前开机时间。看手册就明白了
      

  3.   

    跟Timer差不多,定时器的功能