同一活动的多个通知 [英] Multiple notifications to the same activity

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

问题描述

我有一个正在从通知栏打开的 Activity,但是当我执行 NotificationManager.notify(...) 时,我给意图一个不同的包,以便每个通知打开相同的活动,但从数据库中相互获取其他信息.

I have an activity that is being opened from the notification bar, but when I do NotificationManager.notify(...), I'm giving to the intent a different bundle, so that each notification opens the same activity, but obtaining from the DB other information each other.

但是当我尝试输入任何通知时(例如有 3 个通知),它们都会将我发送到与上一个相同的捆绑包中的活动.尝试了一些标志后,我真的不知道问题出在哪里(一些标志使通知进入第一个捆绑包的活动).

But when I try to enter to any of the notifications (for example there are 3 notifications), they all send me to the activity with the same bundle that the last one. After trying with some Flags, I really don't know where is the problem (some flags makes the notification enter to the activity with the first bundle).

我遵循他们在教程中的使用方式.>

I'm following the way they used it in the tutorial.

推荐答案

如果 PendingIntent 具有相同的操作、动作、数据、类别、组件和标志,它将被替换.

If the PendingIntent has the same operation, action, data, categories, components, and flags it will be replaced.

根据情况,我通常通过提供唯一的请求代码作为静态值 (0,1,2) 或我从数据库接收的数据的行 ID 来解决此问题.

Depending on the situation i usually solve this by providing a unique request code either as static values (0,1,2) or the row id of the data I'm receiving from the DB.

PendingIntent.getActivity(context, MY_UNIQUE_VALUE , notificationIntent, PendingIntent.FLAG_ONE_SHOT);

然后我对 notify() 使用相同的唯一值

Then I use the same unique value for notify() as

mNotificationManager.notify(MY_UNIQUE_VALUE, notification);

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

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