I have set up an alarm to run a service to grab events from the internet. The following is how I implemented it however it seems to run immediately and not delay the alarm at all.
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
开发者_JAVA技巧 am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.currentThreadTimeMillis()+30000, AlarmManager.INTERVAL_DAY, newsAlarm);
Check the AlarmManager documentation, I think you might want to use:
am.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis()+30000, AlarmManager.INTERVAL_DAY, newsAlarm);
I think you want SystemClock.currentTimeMillis()
, not currentThreadTimeMillis()
The thread time is the number of millis since the thread was created. I think you want a real time in this context.
精彩评论