应用程序 crash/force 关闭后添加到警报管理器的警报会消失吗?
Alarms added to alarm manager dies after app crash/force close?
我有一个可以向闹钟管理器添加闹钟的应用程序。当我通过任务杀手强制 close/kill 应用程序时,警报似乎也消失了。我以为它们是独立的?我还有一个警报,定期检查我的应用程序服务是否始终开启...这似乎也与应用程序一起消失了。
这是正常行为吗?
当您强行关闭任务时,它会进入停止状态。在 activity 再次成为 运行 之前,不允许任何服务或广播 运行。这与刚刚下载的应用程序进入的状态相同,在用户启动其中的 activity 之前,服务或广播无法工作。
是,进程的任何警报都将被取消。
@CommonsWare 在 answer 中比我更好地解释了这一点。他还提出了一个可行但不理想的解决方案:
Maintain a record of when your alarm last occurred (e.g., in
SharedPreferences). When your code runs (e.g., LAUNCHER activity is
started), check the last-alarm time. If it was a long time ago, you
know that your alarms were cleared, and so you need to reschedule
them.
我有一个可以向闹钟管理器添加闹钟的应用程序。当我通过任务杀手强制 close/kill 应用程序时,警报似乎也消失了。我以为它们是独立的?我还有一个警报,定期检查我的应用程序服务是否始终开启...这似乎也与应用程序一起消失了。
这是正常行为吗?
当您强行关闭任务时,它会进入停止状态。在 activity 再次成为 运行 之前,不允许任何服务或广播 运行。这与刚刚下载的应用程序进入的状态相同,在用户启动其中的 activity 之前,服务或广播无法工作。
是,进程的任何警报都将被取消。
@CommonsWare 在 answer 中比我更好地解释了这一点。他还提出了一个可行但不理想的解决方案:
Maintain a record of when your alarm last occurred (e.g., in SharedPreferences). When your code runs (e.g., LAUNCHER activity is started), check the last-alarm time. If it was a long time ago, you know that your alarms were cleared, and so you need to reschedule them.