问题
I have programmed an alarm system that synchronizes with the server where are the information.
Sometimes, in the updates on the server some alarms are deleted. Now, it is well removed from the database db4o but I can't cancel pendingIntents already programmed.
Now, I've the following code:
PendingIntent pendingIntent;
public class xxx{
public void updateObjects(){
alarmManager.cancel(pendingIntent);//delete all alarms
(...)
for(...){
//Update each object ofdb4o with the new object value's.
(...)
doIntents(context,mil,obj);
}
(...)
}
public void doIntents(Context context, long mil, ClassObjects obj){
(...)
pendingIntent = PendingIntent.getBroadcast(context, obj.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
(...)
}
}
Can anybody help me to cancel those pendingintents I don't need already?
Thank you!!!
回答1:
for cancel PendingIntent you have to pass same ID
that you passed for set time.
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, obj.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
来源:https://stackoverflow.com/questions/12257128/unable-cancel-pendingintents-android