简体   繁体   中英

How maintain GCM push message in Android, its replaced by new one

My Android application receives push notification with some text messages.If I tap a push it redirects me to desired activity with latest push message (intent message) but I want to show my desired activity with corresponding push messages. For example If I receives 10 push notifications and I tap 3rd notification, my code redirects me to the specified activity with 10th push notification's message, but I want to show 3rd intent push notification's message.

I know PendingIntent.FLAG_UPDATE_CURRENT replace the intent message, how can I redirect with corresponding message instead last message?

I have tried the following:

Intent intent = new Intent(this, TestActivity2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
        | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("uid", uid);

PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0,
        intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
        getApplicationContext());
Notification notification = mBuilder
        .setSmallIcon(R.drawable.ic_launcher)
        .setTicker(textMsg)
        .setWhen(0)
        .setAutoCancel(true)
        .setContentTitle(textMsg)
        .setStyle(
                new NotificationCompat.BigTextStyle().bigText(textMsg))
        .setContentIntent(resultPendingIntent).setContentText(textMsg)
        .build();

NotificationManager notificationManager = (NotificationManager) getApplicationContext()
        .getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) System.currentTimeMillis(),
        notification);

请改用FLAG_ONE_SHOT然后将getActivity的第二个参数更改为0。 答案将使之很清楚。

You should Change the pendingIntend's content for Different Messages. Here is the snippet from PendingIntent document. "A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it. If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid, and can thus call cancel() to remove it."

In simple words...try passing different id(Something like currentEpochTime) for each pendingIntent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM