未在 pendingIntent 中更新的额外值

Tus*_*har 3 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);
Run Code Online (Sandbox Code Playgroud)

Adr*_*oni 9

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

要创建 PendingIntent 尝试:

PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, id, closeButton, PendingIntent.FLAG_CANCEL_CURRENT);
Run Code Online (Sandbox Code Playgroud)