2013-12-17 78 views
0

我希望我的應用程序在經過一段時間後執行某個操作(最好在應用程序未打開或暫停時)。倒計時

例子:

If(hours4 == elapsed){ 

    this.close(); 
} 

回答

0

這很簡單。您必須在後臺使用Service開始此任務。要延遲您可以使用AlarmManager。 Here is example

或處理

新的處理程序()。postDelayed(新的Runnable(){

public void run() { 
     Intent intent = new Intent("INTENT_WAKEUP_B"); 
         intent.putExtra("EXTRA_MESSAGE",message); 
         sendBroadcast(intent); 
    } 
}, timeToWait * 1000); // * 1000 if timeToWait is in seconds 
+0

如果answear是有幫助的,解決你的問題,接受問題 – Serafins

1

使用AlarmManager安排事件在將來某個時間運行。