1.线程休眠
new Thread(new Runnable(){
public void run(){
Thread.sleep(XXXX);
//执行代码
}
}).start();
}
new Thread(new Runnable(){
public void run(){
SystemClock.sleep(XXXX);
//执行代码
}
}).start();
}
2.发送延时消息(推荐)
new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
//执行代码
return false;
}
}).sendEmptyMessageDelayed(0, XXX);
3.线程延时执行
new Handler().postDelayed(new Runnable(){
public void run() {
//执行代码
}
}, XXX);
4.设置定时器
TimerTask task = new TimerTask(){
public void run(){
//执行代码
}
};
Timer timer = new Timer();
timer.schedule(task, XXX);