开发者

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

开发者 https://www.devze.com 2023-02-07 04:22 出处:网络
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.

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

精彩评论

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