android中延迟执行某个任务
2017-07-14 13:23
232 查看
下面是三种方法:
一、线程
[html] view
plaincopy
1. new Thread(new Runnable(){
2. public void run(){
3. Thread.sleep(XXXX);
4. handler.sendMessage();----告诉主线程执行任务
5. }
6. }).start
二、延时器
[html] view
plaincopy
1. TimerTask task = new TimerTask(){
2. public void run(){
3. //execute the task
4. }
5. };
6. Timer timer = new Timer();
timer.schedule(task, delay);
三、Android消息处理
[html] view
plaincopy
new Handler().postDelayed(new Runnable(){
public void run() {
//execute the task
}
}, delay);
四、利用AlarmManager,特点时刻广播指定意图 能实现,一般的简单任务不这么做。
推荐使用第三种
一、线程
[html] view
plaincopy
1. new Thread(new Runnable(){
2. public void run(){
3. Thread.sleep(XXXX);
4. handler.sendMessage();----告诉主线程执行任务
5. }
6. }).start
二、延时器
[html] view
plaincopy
1. TimerTask task = new TimerTask(){
2. public void run(){
3. //execute the task
4. }
5. };
6. Timer timer = new Timer();
timer.schedule(task, delay);
三、Android消息处理
[html] view
plaincopy
new Handler().postDelayed(new Runnable(){
public void run() {
//execute the task
}
}, delay);
四、利用AlarmManager,特点时刻广播指定意图 能实现,一般的简单任务不这么做。
推荐使用第三种
相关文章推荐
- android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- android开发中延迟执行任务方法
- (转)Android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- android延迟执行任务(刷新按钮旋转)
- android中延迟执行某个任务
- android中延迟执行某个任务
- android中延迟执行某个任务
- Android中延迟执行某个任务
- android中延迟执行某个任务