【发布时间】:2010-06-09 19:11:52
【问题描述】:
我的应用程序中发生了警报,它会启动一个通知,然后在按下该通知时会启动一个活动。 问题是,当我创建多个警报时,从通知启动的活动会获得与第一个警报相同的附加功能。我认为问题在于我放入待处理意图的意图或待处理意图本身。我想我可能需要在其中一个上加个标志,但我不知道是哪一个。
Intent showIntent =new Intent(context, notificationreceiver.class);
showIntent.putExtra("details", alarmname);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
showIntent, 0);
notification.setLatestEventInfo(context, "The event is imminent",
alarmname, contentIntent);
以及通知的接收者
Bundle b = getIntent().getExtras();
String eventname = b.getString("details");
details.setText(eventname);
每次下一次通知发生时,额外的“详细信息”都是相同的,而不是具有不同的值。 在我设置意图之前,我确信正确的值会出现在“详细信息”中,因此每次按下任何通知时都会出现第一个意图的问题。 我怎样才能让它启动正确的意图? 希望我尽可能清楚 谢谢!
【问题讨论】:
-
我所做的是因为我使用唯一的 notificationId 来跟踪状态(状态栏通知),我使用相同的变量传递到我的 PendingIntent 从而使其独一无二。
标签: android notifications android-intent