0
我有一些10活動時,本活動處於空閒狀態,持續10秒,那麼它應該返回到主界面如何殺死線程時,新的活動已啓動,如何覆蓋前一個線程
代碼我在每個活動中使用的是
final Handler handler=new Handler();
final Runnable r = new Runnable()
{
public void run()
{
handler.postDelayed(this, 10000);
Intent intent = new Intent(Business_Personal.this,PrintoActivity.class);
startActivity(intent);
Thread.interrupted();
}
};
handler.postDelayed(r, 10000);
Thread thread = new Thread()
{
@Override
public void run() {
try {
while(true)
{
sleep(1000);
handler.post(r);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
如果當時我用這個上面的代碼,直到第三次活動其工作正常,但在第3次活動時間出來了,要回來的主網頁
我需要的代碼時我進入下一個活動,它應該殺死前一個線程並創建一個新的線程
否則
覆蓋以前的線程
感謝您的回覆,但線程正在運行前景instad背景屏幕爲空 –