相同通知 ID 的 Android 通知更新 [英] Android Notification Update for same notification id

查看:77
本文介绍了相同通知 ID 的 Android 通知更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用相同的通知 ID 来显示我的应用程序的通知.我正在传递一个旨在启动活动的对象.问题是对于相同的通知 ID,android 缓存了随意图传递的初始对象.

I am using the same notification id to show the notification of my app. I am passing an object with the intent to launch the activity. The issue is for same notification id, android caches the initial object which is passed along the intent.

那么我怎样才能确保在意图中添加了最新的对象.

So how can I make sure that the latest object is added in the intent.

或者我如何检查通知面板中是否没有清除带有该 ID 的通知,如果存在,我可以删除该通知并创建一个新通知.

Or how can I check if a notification with the id is not cleared in the notification panel and if it's there then I can delete the notification and create a new one.

注意:- 我想避免使用新通知 ID 的情况,因为它会不断创建新通知而不删除旧通知.

Note :- I want to avoid the scenario to use new notification id as that keeps creating new notification without removing the older ones.

推荐答案

在 Pending Intent 中使用 PendingIntent.FLAG_UPDATE_CURRENT,如下所示

Use PendingIntent.FLAG_UPDATE_CURRENT in your Pending Intent like below

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,NotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, NotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

这篇关于相同通知 ID 的 Android 通知更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆