在活动中获取包

时间:2015-10-01 09:47:51

标签: android android-activity push-notification bundle

我创建通知并添加Intent以启动Activity。

Intent intent = new Intent(this, PriceActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Bundle bundle = new Bundle();
    bundle.putString(ID_ORDER, idOrder);
    intent.putExtras(bundle);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setContentTitle("GCM Notification");
    mBuilder.setSmallIcon(R.drawable.ic_launcher);
    mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText("Text"));
    mBuilder.setAutoCancel(true);
    mBuilder.setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(0, mBuilder.build());

在活动中 PriceActivity 获取旧数据。这些数据是在过去的尝试中发现的。

代码获取数据捆绑:

Bundle bundle = getIntent().getExtras();
    final String idOrder = bundle.getString(GcmIntentService.ID_ORDER);
    Log.i("idOrder", idOrder);

有什么问题?

1 个答案:

答案 0 :(得分:1)

Android正在重用旧的PendingIntent。要更新" extras",您需要在{/ p>中使用PendingIntent.FLAG_UPDATE_CURRENT

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);