我有下面的代码创建从服务通知。
我试着发送不同的值在额外的仍然得到最后一个设置值每次在接收器。
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中唯一改变的是额外的和操作,然后为了优化的目的,android正在重用旧的intent。尝试用pendingentent.flag_update_current更改pendingentent.flag_cancel_current
要创建PendingEntent,请尝试:
PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, id, closeButton, PendingIntent.FLAG_CANCEL_CURRENT);