【发布时间】:2011-03-27 20:56:53
【问题描述】:
我正在尝试定期执行一项操作。我想在每 3 秒后创建一个类的新实例。最好通过使用处理程序或线程来实现这一点?我可以尝试一种更简单、更愚蠢的方法吗?我真的不擅长使用线程——我想学习,但更重要的是在担心良好的编程实践之前让它发挥作用。
new Thread(){
public void run(){
//makes sure the player still has 3 lives left
while(game == false){
uiCallback.sendEmptyMessage(0);
try {
Thread.sleep(2000); // wait two seconds before drawing the next flower
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //sleep for 2 seconds
}
}
}.start();
【问题讨论】:
标签: android multithreading handler