2

I am developing an android app where I am trying to set an alarm on daily basis.And for that I am using Calendar as

                alarmCalendar.set(Calendar.DATE,taskdate);
                alarmCalendar.set(Calendar.MONTH, 7);
                alarmCalendar.set(Calendar.YEAR, 2013);
                alarmCalendar.set(Calendar.HOUR, 11);
                alarmCalendar.set(Calendar.MINUTE, 30);
                alarmCalendar.set(Calendar.SECOND, 0);

I was setting the alarm using the below code.

     alarmtime = alarmCalendar.getTimeInMillis();
     am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, AlarmManager.INTERVAL_DAY, pi); 

The Problem with the above code is, the alarm triggers sometimes and sometimes it doesn't.

So I am trying it out in one more way. that is, Once the alarm triggers, On cancel of that alarm I am trying to set it for the next day using

                am.set(AlarmManager.RTC_WAKEUP, currenttime, pendingIntent);

instead of am.setRepeating(). But now the problem is that, even though there is no looping in the code, the alarm triggers continuously on cancelling it.

Not getting where I am going wrong. Please Help.Thanks!

sanjana
  • 641
  • 2
  • 15
  • 36

1 Answers1

-1

Do you have a BroadcastReceiver with the BOOT_COMPLETED permission to recreate the alarm every time the phone starts up? Otherwise you'll loose the alarm.

Check it out here http://learnandroideasily.blogspot.nl/2013/07/bootcompleted-broadcastreceiver-in.html

noloman
  • 11,411
  • 20
  • 82
  • 129
  • The problem is not on BootUp...The Alarm is not triggering properly sometimes. and On cancel , it is triggering continuously.. – sanjana Aug 12 '13 at 09:12