0

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);
M.A.Murali
  • 9,988
  • 36
  • 105
  • 182

2 Answers2

0

Use FLAG_ONE_SHOT instead and change the second parameter in getActivity which is set to 0. This answer will make it clear.

Community
  • 1
  • 1
Kay_N
  • 987
  • 5
  • 12
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.

Madan
  • 1
  • 1