【发布时间】:2015-11-03 22:23:38
【问题描述】:
我的IntentService 中有一个ArrayList,我在其中添加了用户Name 和Message 等元素。
private ArrayList<ShoutData> shoutList = new ArrayList<>();
每次服务收到新通知时都会添加一个新名称和消息。
ShoutData data = new ShoutData();
data.setName(name);
data.setShout(shout);
shoutList.add(data);
resultIntent.putParcelableArrayListExtra(SHOUT_ARRAY, shoutList);
因此,当单击通知时,它应该会导致我可以检索整个 ArrayList(具有多个名称和消息)的活动。然而,只有最后一个通知中的名称和消息最终位于 ArrayList 中。
我需要的是从我收到通知的用户那里获取所有名称和消息。我该如何解决这个问题?我认为问题在于 ArrayList 每次新通知到来时都会重新创建,并且只添加当前通知中的名称和消息(名称和消息需要存储,直到单击通知/意图叫做)。因此,这些元素不会一次全部添加,而是在收到每个通知时一个一个添加。顺便说一下pendingIntent:
PendingIntent.FLAG_UPDATE_CURRENT
如果需要任何其他代码,请发表评论。
【问题讨论】:
标签: java android android-intent arraylist notifications