android - 最新的本地通知覆盖前一个
问题描述
我使用呼叫操作创建本地通知。通知使用以下代码触发,每个通知都有不同的通知 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。有什么问题?
解决方案
我想删除标志PendingIntent.FLAG_UPDATE_CURRENT
会有所帮助:
PendingIntent pendingIntent = PendingIntent.getService(
mContext, notificationId, myIntent, 0);
推荐阅读
- r - 在单独的列中经过每小时后获取字符列的模式?
- python - Django获取模型日期字段值
- matplotlib - 使用 Matplotlib 时 Jupyter 笔记本中的条形图和显示问题
- python - 从列标题到列值
- c - 将用户的输入写入二进制文件
- java - 如何通过按键盘上的左右箭头键来更改背景颜色?(不在钟内,在钟外)
- python - 如何在 python3 中转换 php md5(sha1(time()))?
- javascript - react 应用程序刷新后如何从本地存储中强制注销或删除令牌?
- coordinates - 平面切割球体
- rust - Rust 中的“Cell”可以安全地用于“Rc”吗?