2016-01-21 21 views

回答

11
-1

是的,但這取決於你需要做什麼。

可以例如使用System.Threading.Timer(.NET類)的活性/服務

private System.Threading.Timer timer; 

在活動的OnCreate

TimeSpan timerTime = new TimeSpan(0, 0, 0, 0, 1000); 
      timer = new System.Threading.Timer(new System.Threading.TimerCallback(OnTimerFired), null, timerTime, timerTime); 

在活動的OnDestroy

if (timer != null) 
      { 
       timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); 
       timer.Dispose(); 
       timer = null; 
      } 


private void OnTimerFired(object state) 
{ 
    Do some periodic job 
} 
+0

謝謝。但我實際上想在未加載應用程序時在後臺運行任務。 –

+0

因此,您可以在後臺使用自己的輔助服務,該服務將持續運行,並將「管理」主應用程序。 或某些「調度程序」 http://stackoverflow.com/questions/14376470/scheduling-recurring-task-in-android – Majkl

相關問題