Android延时执行的方法

机构:深圳达内IT教育 时间:2016-07-19 点击:802

  第一种:利用定时器

  TimerTask task = new TimerTask(){

  public void run(){

  //execute the task

  }

  };

  Timer timer = new Timer();

  timer.schedule(task, delay);

  // http://www.android-study.com/jichuzhishi/536.html

  第二种:开启新线程

  new Thread(new Runnable(){

  public void run(){

  Thread.sleep(XXXX);

  handler.sendMessage(); //告诉主线程执行任务

  }

  }).start

  第三种:

  new Handler().postDelayed(new Runnable(){

  public void run() {

  //execute the task

  }

  }, delay);

  更多资讯,请访问深圳Android培训学校

下一篇:Android内核
返回顶部