首页 > 解决方案 > 最新的本地通知覆盖前一个

问题描述

我使用呼叫操作创建本地通知。通知使用以下代码触发,每个通知都有不同的通知 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。有什么问题?

标签: androidandroid-notificationsandroid-pendingintentandroid-alarms

解决方案


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

PendingIntent pendingIntent = PendingIntent.getService(
        mContext, notificationId, myIntent, 0);

推荐阅读