最新的本地通知将覆盖前一个通知

时间:2019-03-08 13:14:38

标签: android android-notifications android-pendingintent android-alarms

我通过 Call 操作创建本地通知。通知将使用以下代码触发,并且每个通知具有不同的通知ID:

Intent myIntent = new Intent(mContext, NotificationService.class);
    myIntent.putExtra("phoneNumber", phone);
    myIntent.putExtra("notificationId", notificationId);

AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(ALARM_SERVICE);
            PendingIntent pendingIntent = PendingIntent.getService(mContext, notificationId, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            alarmManager.set(AlarmManager.RTC_WAKEUP, startTime, pendingIntent);

然后在NotificationService.class中创建并显示通知 notificationManager.notify(notificationId, mBuilder.build());

我以几秒钟的间隔触发两个通知,两个通知都在状态栏中可见。 假设第一个必须对 1111 进行调用,第二个对 2222 进行调用。 如果我按第一个的呼叫操作,它将呼叫 2222 。怎么了?

1 个答案:

答案 0 :(得分:0)

我想删除标志PendingIntent.FLAG_UPDATE_CURRENT会有所帮助:

PendingIntent pendingIntent = PendingIntent.getService(
        mContext, notificationId, myIntent, 0);
相关问题