到相同的活性多个通知 [英] Multiple notifications to the same activity

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

问题描述

我有一个正在从通知栏打开一个活动,但是当我做 NotificationManager.notify(...),我给的意图不同束,使得每一个通知打开相同的活性,但是从DB其他信息取得彼此

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.

根据不同的情况,我通常通过提供一个独特的请求,code无论是作为静态值(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);

然后,我使用的通知()相同的唯一值

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

mNotificationManager.notify(MY_UNIQUE_VALUE, notification);

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

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