【问题标题】:Why wont this work android canceling Alarm?为什么这不起作用android取消警报?
【发布时间】:2014-01-01 22:04:09
【问题描述】:

这是设置警报的原因

    public void setSilent(Long taskId, Calendar when){
     Intent i = new Intent(mContext, SilentReceiver.class);
     PendingIntent pi = PendingIntent.getBroadcast(mContext, 1 , i, PendingIntent.FLAG_ONE_SHOT);
     mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi);

它需要一个 id 和 date 与意图一起使用。 当用户单击删除时,我正在另一个文件中取消它。使用

Intent i = new Intent(null, SilentReceiver.class);
         PendingIntent pi = PendingIntent.getBroadcast(null, 1 , i, PendingIntent.FLAG_ONE_SHOT);

是否应该这样做,因为它与第一个请求代码相同,还是我做错了什么?

【问题讨论】:

标签: android


【解决方案1】:

您必须保存对您的第一个 PendingIntent 的引用。这样你就可以使用:

mAlarmManager.cancel(pi);

并且应该取消警报。

这个答案已经重复了很多次。提问前请先搜索。

【讨论】:

    【解决方案2】:

    小心发送PendingIntent 以停止警报,其数据与创建警报的Intent 相同:problem with cancel the alarm manager pending intent

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多