对同一活动的多个通知

Dan*_*iel 38 android android-intent notificationmanager android-pendingintent

我有一个从通知栏打开的活动,但是当我这样做时NotificationManager.notify(...),我将意图赋予不同的捆绑,以便每个通知打开相同的活动,但从DB获取彼此的其他信息.

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

我按照他们在教程中使用它的方式.

roc*_*dev 107

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

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

PendingIntent.getActivity(context, MY_UNIQUE_VALUE , notificationIntent, PendingIntent.FLAG_ONE_SHOT);
Run Code Online (Sandbox Code Playgroud)

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

mNotificationManager.notify(MY_UNIQUE_VALUE, notification);
Run Code Online (Sandbox Code Playgroud)

  • 我有同样的问题,这个解决方案完美无缺.我认为问题始于[文档](http://developer.android.com/reference/android/app/PendingIntent.html#getActivity%28android.content.Context,%20int,%20android.content.Intent,% 20int%29) - 声称请求代码当前没有被使用,但它似乎是.谢谢你的回答. (7认同)
  • 这对我也有用.请将其标记为解决方案. (5认同)