1、Handler的postDelayed方法
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//do what you want
}
}, 2000); //延时2秒
2、Timer + TimerTask方法
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//do what you want
}
}, 2000); //延时2秒
3、Thread的sleep方法
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000); //延时2秒
} catch (InterruptedException e) {
e.printStackTrace();
}
//do what you want
}
}).start();
4、AlarmManager + Service(BroadcastReceiver)