postDelayed是延迟多少时间再post,postAtTime是在设定的目标时间再post

解决方案 »

  1.   

    如果时间很长,就建议使用AlarmManager
      

  2.   

    各位前辈,以上的答案我baidu google过了,精确时间

    延迟时间我也知道能不能用代码来演示一下这2种的区别?
      

  3.   


    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,这个是用着欢迎页面的自动跳转
      

  4.   

    楼上前辈,隔几秒postAtTime也能实现,具体有什么区别?
      

  5.   

    请查看doc resources list of articles.update the ui from a timer
      

  6.   

    上面的关于 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(). 
      

  7.   

    还是有些不明白,比如我设置一个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",并没有延迟啊~?