Multiple notifications to the same activity

僤鯓⒐⒋嵵緔 提交于 2019-11-26 12:58:25

问题


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.

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.


回答1:


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

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);


来源:https://stackoverflow.com/questions/6066363/multiple-notifications-to-the-same-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!