当应用程序被强制关闭AlarmManager不起作用应用程序、不起作用、AlarmManager

2023-09-06 00:45:12 作者:☆↗菠蘿魚↖☆

文档 AlarmManager startes了

Documentation for AlarmManager startes that

注:报警管理的目的是为您希望让自己的应用code运行在特定的时间的情况下,即使你的应用程序当前未运行。对于正常的定时操作(蜱,超时,等等)更容易和更有效地使用处理程序

Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.

不过,一旦我的应用程序被关闭(强制关闭从任务管理器)我的报警器不工作和的onReceive 方法不会被调用广播接收器内。 我瞄准4.x版。

However, once my application is closed (force close from task manager) my alarm does not work and the OnReceive method is never called inside the broadcast receiver. I am targeting 4.x.

这是怎么回事?

推荐答案

什么@Shrikant说是pretty的很好的解决。

What @Shrikant says is pretty much the answer.

的时间越长verison是,它是假定由机器人出了某种错误与应用程序,如果用户不得不手动强制关闭它。因此相关的应用程序的所有活动(BroadcastReceiver的年代,报警等)不会被启动,直到该应用被用户手动运行至少一次。例如,应用程序的启动的BroadcastReceiver不会当设备被关闭,在这种状态下,直到用户运行的应用程序,那么的下一步的设备引导事件将被传递到应用程序的BroadcastReceiver的调用。

The longer verison is that it is assumed by Android that something is amiss with the app if the user had to force close it manually. Therefore all activities (BroadcastReceiver's, alarms, etc) related to the app will not be initiated until the app is run manually by the user at least once. For example, app's boot BroadcastReceiver will not be called when device is turned off and on in this state until the user runs the app, then the next device boot event will be delivered to the app's BroadcastReceiver.

此行​​为被确认为设计由Android框架开发者:https://groups.google.com/forum/?fromgroups=#!topic/android-developers/anUoem0qrxU

This behavior is confirmed as by design by Android framework devs: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/anUoem0qrxU

*编辑的语法和放大器;添加了一个例子行为

*edited for grammar & added an example behavior