periodicaly运行的任务(每天一次/一周一次) [英] Running task periodicaly(once a day/once a week)

查看:152
本文介绍了periodicaly运行的任务(每天一次/一周一次)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要运行一些任务(即让我的网站的新闻网页)定期(每周一次/天),即使我的应用程序关闭。可能吗?

I want to run some task (i.e. get my web site news page) periodically (once a week/ a day), even if my application is closed. Is it possible?

推荐答案

的确是这样,你需要看的 AlarmManager 设置中反复出现的报警。这是更好地为电池寿命的装置上,作为不同于服务不会在后台不断地运行。报警触发广播接收机将执行您的自定义code。

Yes it is, you need to look at the AlarmManager to setup a reoccurring "Alarm". This is better for battery life on the device, as unlike a service it does not run constantly in the background. The Alarm triggers a broadcast receiver which will execute your custom code.

最后一点 - 有用于报警的时机枚举值,包括每日,每日的一半,还有更多,虽然你可以设定一个实际值

As a final note - there are enum values for the timing of the Alarm including daily, half daily and many more although you can just set an actual value.

一个很好的例子可以发现,在后续的SO后:

A good example can be found in the follow SO post:

报警管理举例

这篇关于periodicaly运行的任务(每天一次/一周一次)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆