首页 > 系统 > Android > 正文

android开发:延时

2019-11-09 15:45:45
字体:
来源:转载
供稿:网友

1、定时器

TimerTask task = new TimerTask(){    public void run(){         //逻辑  }    };    Timer timer = new Timer();  timer.schedule(task, 500);//延时0.5秒 

2、消息

new Handler().postDelayed(new Runnable(){    public void run() {    //逻辑    }    }, 500);//延时0.5秒 

3、线程,因为sleep的原因不推荐

try{	Thread thread = Thread.currentThread();	thread.sleep(500);//延时0.5秒}catch (InterruptedException e) {	e.PRintStackTrace();}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表