通过 Intent 将变量传递给活动始终是相同的
我的应用程序接收 C2DM 消息并随 C2DM 消息发送状态错误通知。到目前为止,一切都很好。 当用户单击通知时,将调用一个活动,并将 C2DM 消息作为变量传递。
现在,第一次运行顺利,第二次传递的变量就没有刷新了。它始终是第一个传递的变量。 我错过了什么吗?
以下是片段:
C2DM 通知
Intent notificationIntent = new Intent(context, BMBPad.class);
notificationIntent.putExtra("seqid", message);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
这是我读取 Intent 调用的 Activity 中的变量的方式。
extra = this.getIntent().getExtras();
seqidi = extra.getString("seqid");
有人知道为什么会发生这种情况吗?
My application receives a C2DM message and sends a status bad notification with the C2DM message. So far so good.
When the user clicks on the notification, an activity is called, passing the C2DM message as a variable.
Now, the first time it works smoothly, the second time the variable passed is not refreshed. It's always the first variable passed.
Am I missing something?
Here are the snipperts:
C2DM Notification
Intent notificationIntent = new Intent(context, BMBPad.class);
notificationIntent.putExtra("seqid", message);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
This is how I read the variable in the Activity called by the Intent.
extra = this.getIntent().getExtras();
seqidi = extra.getString("seqid");
Anyone any idea why that happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用标志
PendingIntent.FLAG_UPDATE_CURRENT
在您的情况下:
另请查看此处:Android PendingIntent
You need to use the flag
PendingIntent.FLAG_UPDATE_CURRENT
In your case:
Please also have a look here: Android PendingIntent
您可以尝试将此代码段附加到 Intent 调用的 Activity 中。
You can try to append this snippet in the Activity called by the Intent.
重写 onNewIntent() 方法,像这样获取变量:
}
因为再次启动活动将触发 onNewIntent() 方法。
override onNewIntent() method, get your variable like this:
}
because start the activity again will trigger onNewIntent() method.