我正在通过以下代码在BroadcastReceiver中创建一个通知:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
int icon = R.drawable.ic_stat_notification;
CharSequence tickerText = "New Notification";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_VIBRATE;
long[] vibrate = {0,100,200,200,200,200};
notification.vibrate = vibrate;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
CharSequence contentTitle = "Title";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(context, NotificationActivity.class);
notificationIntent.putExtra(Global.INTENT_EXTRA_FOO_ID, foo_id);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
int mynotification_id = 1;
mNotificationManager.notify(mynotification_id, notification);
当我单击通知时,它将打开NotificationActivity,并且在Activity中可以从Intent-Bundle中检索foo_id(例如1)
但是,如果触发了另一个通知并再次单击它,则该活动仍会从Intent-Bundle中接收到“旧”值(1)。我试图用clear()清除捆绑包,但是收到了同样的效果。我认为我的代码有误。
请告诉我如何从待定意图中获取数据
—
user49557
意识到它正在发送旧的临时演员,使我的分诊更加容易。
—
Utsav Gupta