Thread thred = new Thread();
thred.run();
public void run() {
while (true)
{
try {
Thread.sleep(500);
Toast toast = Toast.makeText(getApplicationContext(), "Sleep Over", 100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
Toast toast = Toast.makeText(getApplicationContext(), "Sleep NOT Over", 100);
}
}
此代码不起作用
答案 0 :(得分:0)
Thread thred = new Thread()
{
public void run() {
while (true)
{
try {
sleep(500);
Toast toast = Toast.makeText(getApplicationContext(), "Sleep Over", 100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
Toast toast = Toast.makeText(getApplicationContext(), "Sleep NOT Over", 100);
}
}
}
};
thred.start();
你需要调用当前线程的sleep方法Thread.sleep将调用静态sleep方法。您需要确保使用自己的run方法覆盖线程类的run方法,然后调用thread.start不运行。