您的位置:首页 > 移动开发 > Android开发

Android 延时执行操作方法

2016-03-21 14:20 375 查看
下面是三种方法:

一、线程

[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();

三、android消息处理

[html] view plaincopy
new Handler().postDelayed(new Runnable(){
public void run() {
//execute the task
}
}, delay);

推荐使用第三种
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: