0

我在活動A. 建立AlarmManagerPendingIntent然後我想能夠從不同的活動B.Android:如何在不同的活動中訪問Pending Intent?

的Android文檔調用cancel()在同一PendingIntent說以下內容:

「如果稍後創建的應用程序重新獲取同一種類的PendingIntent(相同的操作,相同的Intent操作,數據,類別和組件以及相同的標誌),它將收到一個代表相同標記的PendingIntent ,因此可以調用cancel()來刪除它。「

是否有可能將PendingIntent存儲在數據庫中 並從不同的活動中檢索它?

回答

1

如果您不是以動態的方式創建PendingIntent,那麼您只需要以相同的方式創建PendingIntent。

我建議創建一個將創建並提供PendingIntent的單例。這樣,你可以在你的應用程序的任何地方調用類似這樣的東西:

PendingIntent pi = PendingIntentHelper.getInstance().buildPendingIntent(); 
am.cancel(pi); 
相關問題