android - pendingIntent 中未更新的额外值

标签 android android-intent android-pendingintent

我有以下代码从服务创建通知。 我正在尝试额外发送不同的值,但每次都在接收方中获取最后一个设定值。

Intent closeButton = new Intent(this,DownloadCancelReceiver.class);
closeButton.putExtra("id",id);
closeButton.setAction("Action"+Long.toString(id));
PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, id, closeButton, PendingIntent.FLAG_UPDATE_CURRENT);

notificationView = new RemoteViews(getPackageName(), R.layout.notification_view);
notificationView.setProgressBar(R.id.pb_progress, 100, 5, false);
notificationView.setOnClickPendingIntent(R.id.btn_close, pendingSwitchIntent);

最佳答案

您在 Pending Intent 中唯一需要更改的是 Extra 和 Action,然后出于优化目的,Android 正在重用旧 Intent。尝试将 PendingIntent.FLAG_UPDATE_CURRENT 更改为 PendingIntent.FLAG_CANCEL_CURRENT

要创建 PendingIntent,请尝试:

PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, id, closeButton, PendingIntent.FLAG_CANCEL_CURRENT);

关于android - pendingIntent 中未更新的额外值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42997350/

相关文章:

android - 透明自适应图标背景

android - 在移动设备上以一个大请求或多个小请求下载数据是否对性能更好?

java - 有意传递文件,我该如何检索它

android - IabHelper 类不起作用?

android - 识别器 Intent : how to add a bundle to a pending intent

android - 检查Android应用程序是否是您的或被反编译假冒

java - 用户从图库或自定义相机中选择图像,而不是图像的相机应用程序

android - Oreo 8.0 中的推送通知问题

android - 取消 PendingIntent

java - fragment 中的 bundle 为空