Are you sure that text_of_last_alarm is still valid between set() and
cancel()?
Unless you save it into persistent storage and restore later, it will be
lost if the process is killed (which does happen :)
Other than that, setting an alarm automatically cancels any previous
alarms set for an equal PendingIntent (where "equal" is well defined in
the docs).
Also worth noting: setType() is for specifying a mime type, not
arbitrary text data (although it shouldn't matter here).
-- Kostya
On 02/14/2012 07:16 PM, Rudolf Polzer wrote:
I use alarms and I use the type of the intent to carry some text.
When the alarm time has changed, I try to cancel the old alarm, but
this doesn't work:
AlarmManager am =
(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent in = new Intent(context, OnAlarmReceiver.class);
in.setType(text_of_last_alarm);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, in, 0);
am.cancel(pi);
This is how I am setting a new or changed alarm - this works:
in = new Intent(context, OnAlarmReceiver.class);
in.setType(text_of_new_alarm);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, in, 0);
am.set(AlarmManager.RTC_WAKEUP, time, pi);
text_of_last_alarm = text_of_new_alarm;
Any Ideas?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en