android Alarmmanager 每月启动一次
我希望 AlarmManager 每个月 5 日下午 3 点执行一项任务。我该怎么做呢?
首次启动取决于用户安装应用程序的时间。好吧,我可以做一些数学计算,计算下个月 5 号需要多少毫秒,但我希望有一种更简单的方法
重复选项让我非常头痛。我只能设置一个固定的间隔。但两个月之间的时间并不固定,因为有时有 30 天,有时有 31 天(更不用说 2 月了)。
我该如何做到最好?
问候, 一个。
I want the alarmManager to perform a task every 5th of the month at 3pm. How would I do that?
first start depends on when the user installs the app. Okay I can do some math calculating how many ms it takes to the next 5th of the month, but I hope there is an easier way
the repeat option gives me a real headache. I only can set one fixed intervall. but the time between two month is not fixed since sometimes I have 30, sometimes 31 days (not to mention Feb).
How would I do this best?
Regards,
A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以更简单地做到这一点,看看 Date 类:
http://developer.android.com/reference/java/util/Date.html并尝试类似 Pseudo:
到了年底,你可能会遇到问题,但问题比现在要少。
还有其他日期 API,其中一些可以为您解决年份问题。看看周围吧。
编辑
刚刚注意到不推荐使用日历:
http:// developer.android.com/reference/java/util/Calendar.html
You can do this much simpler, have a look at the Date class:
http://developer.android.com/reference/java/util/Date.htmlAnd Try something like, Pseudo:
You would have issues when you come to end of the year, but it's less issues than you have at the moment.
There are other Date API's and some will fix the year problem for you. Just have a look around.
EDIT
Just noticed that's deprecated use Calendar:
http://developer.android.com/reference/java/util/Calendar.html