Действие не обновляется при получении намерения

#android #android-pendingintent

#Android #android-pendingintent

Вопрос:

Следующий код выдает один и тот же контент после того, как я отправлю два уведомления с разным контентом, скажем, Content1 и Content2. Результирующая активность всегда показывает только Content2. В чем может быть причина этого?

 public void onReceive(Context context, Intent intent) {
    abortBroadcast();

    mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.icon;
    CharSequence tickerText = intent.getStringExtra("NOTIFICATION_TITLE");
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    CharSequence contentTitle = intent.getStringExtra("NOTIFICATION_TITLE");
    CharSequence contentText = intent.getStringExtra("NOTIFICATION_DETAILS");
    Intent notificationIntent = new Intent(context,CustomActivity.class);
    notificationIntent.putExtra("TITLE", contentTitle);
    notificationIntent.putExtra("DETAILS", contentText);
    //notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    mNotificationManager.notify(notifUUID.hashCode(), notification);


}
  

Ответ №1:

Получил ответ! исправление было простым — просто добавлено: notificationIntent.setAction(строка.valueOf(notifUUID.hashCode()));

Любое уникальное значение (временная метка тоже сработала бы), установленное в качестве действия намерения, сработало бы.