请求postDelayed和postAtTime有什么区别呢?

立志做一个佳娃~ 2012-02-27 12:28:52
请求postDelayed和postAtTime有什么区别呢?
...全文
2822 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Big-Heart 2014-07-28
  • 打赏
  • 举报
回复
引用 8 楼 li674688017 的回复:
没什么区别~~~
还是有些不明白,比如我设置一个Button的点击事件 new Thread(new Runnable() { @ Override public void run() { // TODO Auto-generated method stub Message msg = Message.obtain(); msg.what = 3; handler.sendMessageAtTime(msg, 10000); } }).start(); 然后再设置 private Handler handler = new Handler() { @ Override public void handleMessage(android.os.Message msg) { System.out.println("--what-->"+msg.what); }; }; 我一点击button的时候,logcat中马上显示"--what-->3",并没有延迟啊~?
火把 2012-09-06
  • 打赏
  • 举报
回复
上面的关于 postAtTime 的解释都是错的~
请参考api:
----------------------
public final boolean postAtTime (Runnable r, long uptimeMillis)

Since: API Level 1
Causes the Runnable r to be added to the message queue, to be run at a specific time given by uptimeMillis. The time-base is uptimeMillis(). The runnable will be run on the thread to which this handler is attached.

----------------------
注意时间基数是uptimeMillis().
Marco_Lee 2012-02-27
  • 打赏
  • 举报
回复
如果时间很长,就建议使用AlarmManager
大掌教 2012-02-27
  • 打赏
  • 举报
回复
楼上正解
Marco_Lee 2012-02-27
  • 打赏
  • 举报
回复
postDelayed是延迟多少时间再post,postAtTime是在设定的目标时间再post
  • 打赏
  • 举报
回复
请查看doc resources list of articles.update the ui from a timer
Marco_Lee 2012-02-27
  • 打赏
  • 举报
回复
没什么区别~~~
  • 打赏
  • 举报
回复
楼上前辈,隔几秒postAtTime也能实现,具体有什么区别?
Marco_Lee 2012-02-27
  • 打赏
  • 举报
回复

public class Welcome extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
MyRunnable r = new MyRunnable();
handler.postDelayed(r, 2000);
handler.postAtTime(r, System.currentTimeMillis() + 100000);

}


Handler handler = new Handler();

class MyRunnable implements Runnable {

@Override
public void run() {
Intent intent = new Intent();
intent.setClass(Welcome.this, SecondActy.class);
startActivity(intent);
}

}

}



postDelayed和postAtTime,这个是用着欢迎页面的自动跳转
  • 打赏
  • 举报
回复
各位前辈,以上的答案我baidu google过了,

精确时间

延迟时间我也知道

能不能用代码来演示一下这2种的区别?

80,337

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧