unable cancel PendingIntents - Android

大兔子大兔子 提交于 2019-12-10 11:33:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!