您的位置:首页 > 其它

延时方式整理

2016-01-13 20:47 183 查看

延时的几种方式

2种简单方法
Thread.sleep(100);//需要捕获异常
SystemClock.sleep(200);//不需要处理异常


开启新线程
new Thread(new Runnable(){
public void run(){
Thread.sleep(XXXX);
handler.sendMessage();----告诉主线程执行任务
}
}).start();


利用定时器
TimerTask task = new TimerTask(){
public void run(){
//execute the task
}
};
Timer timer = new Timer();
timer.schedule(task, delay);


使用Handler
new Handler().postDelayed(new Runnable(){
public void run() {
//execute the task
}
}, delay);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  延时 定时