2011-06-25 46 views
17

我需要一個計時器用於我的程序。我寫了它,它在emulalator程序(Android 1.5/2.2)中的PC上運行良好。但它不適用於真正的設備(Android 1.5)。我究竟做錯了什麼?Android中的Timer和TimerTask

TimerTask task = new TimerTask() { 
      public void run() { 
       if (condition) { 
        myFunc(); 
       } else { 
        this.cancel(); 
       } 
      } 
     }; 
     Timer timer = new Timer(); 
     timer.schedule(task, 500, 85); 
+0

可能重複的[Android - 使用Timer和TimerTask控制任務?](http://stackoverflow.com/questions/2161750/android-controlling-a-task-with-timer-and-timertask) –

+0

Go through這[android-controlling-a-task-with-timer-and-timertask](http://stackoverflow.com/questions/2161750/android-controlling-a-task-with-timer-and-timertask) – Rasel

回答

17

您需要取消()定時器而不是定時器任務。

+0

謝謝很多!這解決了我的問題。 – Scit

相關問題