views:

423

answers:

1

Hi all,

I want to set an alarm in my application which will be triggered each day. According to the doc, I have to set a one-time alarm, and in the BroadcastReceiver which will receive the alarm signal, reset the alarm for the day after. Is that correct ?

My BroadcastReceiver handles well the wakelock and launch a service which releases this wakelock. Everything works fine here.

However I have problems. In my application there is a checkbox which is checked when alarm is up. To know if my alarm is up, I use the following condition :

Intent intent = new Intent( context, AlarmReceiver.class );
boolean alarmUp = (
PendingIntent.getBroadcast( context, 0, intent, PendingIntent.FLAG_NO_CREATE) != null)

But this doesn't seem to work very well, is that a good way to know if an alarm is up ?

Thanks in advance

+6  A: 

For the first part of your question, you could just use a repeating alarm, or schedule a new alarm whenever one fires like you are doing. Either way works.

You may also want to setup a broadcast receiver that receives ACTION_BOOT_COMPLETED so you can reschedule your alarms when the phone reboots.

As for checking if the alarm exists, the PendingIntent with FLAG_NO_CREATE is exactly how you would do that.

mbaird
Thanks for your reponse, it seems I'm doing well but why sometimes my alarm checkbox is unchecked while I setted the alarm the day before ?About phone reboots, I already have a receiver which receives the ACTION_BOOT_COMPLETED and sets the alarm.
kosokund
I would make sure that your code isn't failing to reschedule the alarm after one fires. You might have to post more of your code for people to be able to find a bug or something.
mbaird
OK you're probably right. Thx
kosokund