Android通知始终返回我之前的捆绑数据

时间:2015-11-30 19:17:51

标签: android android-intent notifications bundle

我正在尝试获取每次推送通知的新数据, 我正在通过每个新推送通知传递新数据,然后将此数据添加到包中并将其传递给我的活动, 每当我发送推送通知时,我的活动始终使用捆绑中的先前数据。

这是我的代码,

Intent notificationIntent = new Intent(context, Myactivity.class);
        Bundle b = new Bundle();
        b.putString("post_id", newsletter_key);
        b.putString("newsletter_title", message);
        notificationIntent.putExtra("bundle_push", b);

        //notificationIntent.putExtra("NotificationMessage", newsletter_key.toString());

        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        // set intent so it does not start a new activity



        PendingIntent intent =
                PendingIntent.getActivity(context, 0, notificationIntent, 0);


                notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        // Play default notification sound
        notification.defaults |= Notification.DEFAULT_SOUND;

        //notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");

        // Vibrate if vibrate is enabled
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationManager.notify(0, notification);

有任何帮助吗? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

将PendingIntent替换为以下代码

PendingIntent intent= PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

参考 - http://developer.android.com/reference/android/app/PendingIntent.html