我需要每天晚上在午夜运行的服务。我想用AlarmManager做到这一点。
I need to run a service each night at midnight. I would like to use the AlarmManager to do this.
您能给我如何使它正常工作,一些指导?
Can you give me some guidance of how to make it work correctly?
alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, System.currentTimeMillis(), AlarmManager.INTERNAL_DAY, serviceIntent);
也许,我需要使用日历对象指定时间?感谢您的帮助!
Perhaps I need to use a Calendar object to specify the time? Thanks for any help!
setInexactRepeating()
,顾名思义,是不准确的。请记住,它可能之前或午夜之后有些运行。
setInexactRepeating()
, as the name suggests, is inexact. Bear in mind that it might run somewhat before or after midnight.
要确定何时午夜,使用日历
对象。然后调用 GETDATE()
获得日期
和的getTime()
的日期
,以获得正确的毫秒值的 setInexactRepeating()
电话。
To determine when midnight is, use a Calendar
object. Then call getDate()
to get a Date
and getTime()
on the Date
to get the proper millisecond value for your setInexactRepeating()
call.
上一篇:Android的国家列出与标志和获得ISO移动codeS的可用性可用性、标志、国家、Android
下一篇:如何添加和Gmail等Android中,以场空间标记生成器中正常删除联系人气泡multiautocompletetextview气泡、标记、器中、联系人