【问题标题】:When exactly does a PendingIntent get disposed/removed?PendingIntent 究竟何时被处置/移除?
【发布时间】:2012-10-14 15:46:23
【问题描述】:

我使用PendingIntent 以及AlarmManagerBroadcastReceiver 在用户指定的时间显示提醒。我正在使用NotificationManager 显示提醒。

在设置通知之前,我希望按钮说“设置提醒”,设置通知之后,我希望按钮说“更改提醒”。向用户显示通知后,按钮应再次显示“设置提醒”

我正在创建具有相同意图、上下文和相同唯一 ID (myUniqueId) 的相同 PendingIntent,以检查 PendingIntent 是否处于活动状态。

Intent intent = new Intent(context, ReminderReceiver.class);
boolean reminderActive = (PendingIntent.getBroadcast(context, myUniqueId, intent, PendingIntent.FLAG_NO_CREATE) != null);

现在可以正常工作,并且按钮文本可以正确显示。但我发现,一旦显示通知,除非我明确检索相同的PendingIntent 并取消它,否则它会在一段时间内被 NOT 删除。所以有一段时间,按钮仍然显示“更改提醒”。

那么假设除非我明确取消 PendingIntent,否则它仍存储在内存中的某个位置以进行垃圾收集是否正确?

【问题讨论】:

    标签: java android android-intent alarmmanager android-pendingintent


    【解决方案1】:

    所以假设除非我明确取消 PendingIntent 它仍然存储在内存中的某个位置是正确的

    是的。 Android 缓存 PendingIntent 对象。 AFAIK,他们会一直待着,直到进程终止。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-27
      • 2015-10-18
      • 2021-06-03
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      相关资源
      最近更新 更多