开发者

Have a repeating alarm start thirty seconds once started then once a day afterward in Android

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜