下面是三种方法:
一、线程
[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);
推荐使用第三种
本文介绍了在Android应用中使用消息处理机制(Handler.postDelayed)来高效地执行后台任务,避免阻塞主线程,并提供了实现步骤和示例代码。
478

被折叠的 条评论
为什么被折叠?



