0

我的应用程序接收到 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");

有人知道为什么会这样吗?

4

3 回答 3

0

你需要使用标志PendingIntent.FLAG_UPDATE_CURRENT

在你的情况下:

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

也请看这里:Android PendingIntent

于 2012-02-13T22:42:34.347 回答
0

您可以尝试将此代码段附加到 Intent 调用的 Activity 中。

/**
 * Override super.onNewIntent() to let getIntent() fetch the latest intent
 * that was used to start this Activity rather than the first intent.
 */
@Override
public void onNewIntent(Intent intent){
    super.onNewIntent(intent);
    setIntent(intent);
}
于 2016-04-05T16:53:39.960 回答
0

覆盖 onNewIntent() 方法,得到你的变量是这样的:

@Override
public void onNewIntent(Intent intent){
super.onNewIntent(intent);
seqid = intent.getStringExtra("seqid","");

}

因为再次启动活动会触发 onNewIntent() 方法。

于 2016-08-20T15:59:00.897 回答