- new
Thread(new Runnable(){ -
public void run(){ -
Thread.sleep(XXXX); -
handler.sendMessage();----告诉主线程执行任务 -
} - }).start
② 利用定时器
Java代码
- TimerTask
task = new TimerTask(){ -
public void run(){ -
//execute the task -
} - };
- Timer timer = new Timer();
timer.schedule(task, delay);
③
Java代码
- new
Handler().postDelayed(new Runnable(){ -
public void run() { -
//execute the task -
} -
}, delay);