在Android的AlarmManager行为澄清行为、Android、AlarmManager

2023-09-05 11:05:48 作者:七秒

我看到AlarmManager的所有示例由一个活动集。

I see all the examples of AlarmManager being set by an Activity.

我的问题是这样的: 如果我的应用程序设置的重复AlarmManager,这是否甚至开始是从内存中关闭和删除应用后持续?

My question is this: If my application sets a recurring AlarmManager, does that persist even after the application that started is is closed and removed from memory?

如果没有,我怎么开始的AlarmManager在由机器人在启动时启动的较低水平,如果它没有成功或死亡或抛出一个异常被重新启动,而用户不必做什么吗?

If not, how do I start an AlarmManager at a lower level that is started by Android at boot up and if it ever fails or dies or throws an exception is restarted without the user having to do anything?

最后,如果我愿意的BroadcastReceiver的动作进行没有可视化组件,我还是要创建一个单独的活动呢?在我来说,我希望这是一个后台上传,唤醒并期待到一个文件夹,如果它认为该文件夹中的文件,将它们放到服务器上。我不需要任何反馈给用户。

Lastly, if the action I wish for the BroadcastReceiver to undertake has no visual components, do I still have to create a separate Activity for it? In my case I want there to be a background uploader that wakes up and looks into a folder and if it sees files in that folder, sends them off to the server. I don't need any feedback to the user.

所以,我的理想是有一个神奇的,基于操作系统的AlarmManager调用刚刚处理了上传的IntentService,但我不清楚如何获得这样的AlarmManager摆在首位运行。

So, my ideal would be to have a magical, OS based AlarmManager that calls an IntentService which just handles the uploading, but I'm unclear on how to get such an AlarmManager running in the first place.

TIA

推荐答案

是的,AFAIK报警生存,并不断得到触发,即使是注册他们结束活动后。但是,他们没有生存的一个手机重启。

Yes, AFAIK the alarms "survive" and keeps getting triggered, even after the activity that registered them ends. But they don't survive a phone reboot.

如果我正确地理解你的问题,我觉得你可以达到你想要的产品通过创建一个广播接收器监听android.intent.action.BOOT_COMPLETED意图,然后一期工程(重新)注册一个重复报警,这轮流启动(意向)服务做上传。

If I understands your problem correctly, I think you can achieve what your looking for by creating a project with a broadcast receiver that listens for android.intent.action.BOOT_COMPLETED intents and then (re-)register a repeating alarm, which in turns starts a (Intent)Service to do the uploading.

您不需要一个活动,但你可能会想要一个无论如何,让用户暂时禁用检查过的复选框,或者东西上传机制。它很可能也很高兴地让用户选择闹钟的频率,即多长时间的服务,应启动,寻找新的文件上传。这也将是注册你的闹钟在第一次的好地方。

You don't need an activity, but you probably would want one anyway, to let the user temporarily disable the upload mechanism by checking off a checkbox, or something. It would probably also be nice to let the user choose the frequency of your alarm, i.e. how often the service should be started and look for new files to upload. This would also be a good place to register your alarm for the first time.