警报管理器 phone 重启

alarm manager phone rebot

我正在开发一个应该每 15 天后重新出现的应用程序,我的应用程序工作正常,但是如果 phone 重新启动会发生什么,我正在使用广播管理器重新启动 activity.但是有没有办法让警报保持在相同的值,例如如果 phone 在上一个事件发生 3 天后重新启动,那么下一个警报应该会在 12 天内触发。

我还没有看到这个确切的问题,人们通常会问广播接收器,我已经完成了。有什么指点吗?

将闹钟时间存储在文件中是个好主意吗?但是 AlarmManager.INTERVAL_DAY*14 里面是什么?我的示例警报管理器如下:

am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY*15, pi);                          

您需要将值保存在 SharedPreferences 中并使用修改后的闹钟重新启动应用程序。

我会每隔一段时间保存该值,并检测 phone 关闭(使用广播)

是的,一旦设备 rebooted.From android docs

,警报就会被清除

This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

您可以注册 android.intent.action.BOOT_COMPLETED 接收器并重新安排您的 alarm.You 可以将要安排的时间存储在共享首选项或数据库中。