取消AlarmManager的问题

编程入门 行业动态 更新时间:2024-10-28 14:32:16
本文介绍了取消AlarmManager的问题-PendingIntent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个可以提醒人们执行任务的应用程序.因此有一个PendingIntent,现在用户可以在需要时删除警报.在此代码中,只有一个PendingIntent用于多个用户警报,因此我对取消额外意图为"pill"的特定警报感到困惑.剩余的警报不应取消.我对这个问题一无所知.希望我清楚.谢谢

I have an app which reminds people to do their tasks. So there is one PendingIntent, now the user can delete the alarm when he wants to. In this code, there is just one PendingIntent for multiple user alarms so I am confused on cancelling that particular alarm where the intent extras is "pill". The remaining alarms should not be cancelled. I have no clue on this problem. Hope I am clear. Thanks

Intent intent = new Intent(this, AlarmNotifyReceiver.class); intent.putExtra("Name_pill", "pill"); sender = PendingIntent.getBroadcast(this, DatabaseConstants.NOTIFICATION_ID + 1, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(), sender); updateTheFlag(pillName[(pillName.length-1)]);

推荐答案

根据Android文档,为了停止警报,您应该创建一个具有相同数据的Intent,但不是必须是相同的附加功能:

According to the Android documentation, in order to stop an alarm, you should create an Intent with the same data, but not necessarily the same extras:

取消公共无效(PendingIntent操作)

public void cancel (PendingIntent operation)

删除具有匹配意图的所有警报.任何警报,其意图与该警报相匹配的任何类型(由 filterEquals(Intent)定义)都将被取消.

Remove any alarms with a matching Intent. Any alarm, of any type, whose Intent matches this > one (as defined by filterEquals(Intent)), will be canceled.

filterEquals(Intent)

布尔布尔过滤器等于(其他Intent)

public boolean filterEquals (Intent other)

确定两个意图是否相同,以实现意图解析(过滤). >即,如果它们的动作,数据,类型,类和类别相同. 这不会比较意图中包含的任何额外数据.

Determine if two intents are the same for the purposes of intent resolution (filtering). > That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.

更多推荐

取消AlarmManager的问题

本文发布于:2023-11-26 23:55:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AlarmManager

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!