3

我正在使用PendingIntent以及AlarmManagerBroadcastReceiver在用戶指定的時間顯示提醒。我正在使用NotificationManager顯示提醒。何時PendingIntent被處置/刪除?

通知設定之前,我想有一個按鈕,說「設置提醒」和通知設置後,我希望按鈕說「更改提醒」。一旦通知顯示給用戶,該按鈕應該再次說「設置提醒」

我使用相同的意圖,上下文和相同的唯一標識(myUniqueId)創建相同的PendingIntent,以檢查PendingIntent是否處於活動狀態。

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

現在這個工程和按鈕文本顯示正常。但我發現只要顯示通知,除非我明確檢索到相同的PendingIntent並取消它,否則會刪除而不是一段時間。所以有一段時間,按鈕仍然會顯示「Change Reminder」。

因此,假設除非我明確取消PendingIntent,它仍然存儲在內存中的某個地方被垃圾回收是正確的嗎?

回答

1

因此,它是正確的假設,除非我明確取消的PendingIntent它仍然某處存儲在存儲器

是。 Android緩存PendingIntent對象。 AFAIK,他們將繼續前進,直到流程終止。

相關問題