user180825
user180825

Reputation:

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);
        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.currentThreadTimeMillis()+30000, AlarmManager.INTERVAL_DAY, newsAlarm);

Upvotes: 0

Views: 191

Answers (2)

dave.c
dave.c

Reputation: 10908

Check the AlarmManager documentation, I think you might want to use:

am.setRepeating(AlarmManager.RTC_WAKEUP,
            System.currentTimeMillis()+30000, AlarmManager.INTERVAL_DAY, newsAlarm);

Upvotes: 1

Cheryl Simon
Cheryl Simon

Reputation: 46844

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.

Upvotes: 1

Related Questions