0

I'm having a problem with setting an alarm using setRepeating().

Intent i = new Intent(context, OnAlarmReceiver.class);
i.putExtra("id", storable.getId());
PendingIntent pi = PendingIntent.getBroadcast(context, storable.getId(), i, PendingIntent.FLAG_UPDATE_CURRENT);

mgr.setRepeating(AlarmManager.RTC_WAKEUP, storable.getObject().getTimeOnDay(Calendar.FRIDAY), Event.MILLISECONDS_IN_A_DAY*7, pi);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(storable.getObject().getTimeOnDay(Calendar.FRIDAY));
Log.v("ACTUALLY SCHEDULED ON FRIDAY", c.getTime().toString());

Logcat states: 09-28 02:17:58.535: V/ACTUALLY SCHEDULED ON FRIDAY(32494): Fri Oct 05 01:43:00 EDT 2012

which is the correct time that I scheduled. However, my alarm does not trigger. The only clue I have as to what may be causing this is that when i step into the method using the debugger, one of the methods that is called is Parcel.readException(). I do not know what this means or if it is even actually important. Does anybody have a clue what might be going on?

Tom C
  • 232
  • 1
  • 6
  • 17

2 Answers2

0

Refer this link. It was also asked by Tom and CommonsWare gave a pretty good answer to that.

EDIT:

See if this helps:

    Intent myIntent = new Intent(context, OnAlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, myIntent, 0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60, pendingIntent);
Community
  • 1
  • 1
Name is Nilay
  • 2,743
  • 4
  • 35
  • 77
  • This is the code that i used to build this code and it is almost exactly the same except I use system time instead of elapsed time and so my first flag parameter is different. – Tom C Sep 28 '12 at 06:54
  • This code is almost exactly the same as the code thats implemented (Calendar.add() is done in getTimeOnDay().) The time is correct I am positive from the log. – Tom C Sep 28 '12 at 07:32
  • Then have you registered your Receiver in Manifest file...because I am getting desired output from this code..!! – Name is Nilay Sep 28 '12 at 07:59
  • That is very strange. I have the line in my code and other methods call this reciever that work properly. – Tom C Sep 28 '12 at 08:02
0

I found the answer. This method was being called multiple times, and using the same value from storable.getId() in the PendingIntent. It was overwriting the old PendingIntent and scheduling another one that I did not wait for. Thanks to those of you who helped.

Tom C
  • 232
  • 1
  • 6
  • 17