Skip to content Skip to sidebar Skip to footer

Notification And Alarmmanager

I know that this question has been asked several times but I really don't understand why my code doesn't work. I based upon a lot of examples (from stackoverflow answers) to write

Solution 1:

set() on Calendar does just that: it sets the value. As a result, the date may be in the past, given your existing code.

For example, where I am, right now it is Friday. So, the object returned by Calendar.getInstance() is set for now, which means its day-of-week will be Friday. If you call set() to change that to Tuesday, now you may be setting a date in the past. Similarly, even if you were to set the day-of-week to Friday, it is after 8am where I am, and therefore you would be creating a date that is in the past.

You need to check your calculated Calendar object and see if it is in the past. If it is, add 7 days to move it to the next week's time for the alarm to go off.

Also, note that an RTC alarm will not wake up the device out of sleep mode. That may be fine for your purposes, but I just wanted to make sure that you were aware of this.

Post a Comment for "Notification And Alarmmanager"