0

我希望我的应用程序在经过一定时间后执行操作(最好是在应用程序未打开或暂停时)。

例子:

If(hours4 == elapsed){

    this.close();
}
4

2 回答 2

1

使用 AlarmManager 安排事件在未来运行。

于 2013-12-17T21:34:46.587 回答
0

这很简单。您必须在后台使用Service. 要延迟,您可以使用 AlarmManager。这是示例

或处理程序

新的 Handler().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
于 2013-12-17T21:35:24.493 回答