2013-12-17 79 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安排事件在将来某个时间运行。