我在下面的代码中创建了通知服务。 我试图发送不同的值,每次在接收器中获得最后的设置值。
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);
答案 0 :(得分:1)
您在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);