I have ArrayList of object that I query from database and I want to notify all of my objects to remove them when user touch on notification.
I put each id of my object to intent and start intent to remove it but the problem is when I touch on notification the id of first item is correct but but the others is not it stills the first id.
This is the code
for(int i=0;i<listItem.size();i++){
String message = "Remove \""+listItem.get(i).getName()+"\" "+listItem.get(i).getID();
intent.putExtra("id", listItem.get(i).getID());
String s = intent.getExtras().getString("ID");
Toast.makeText(getApplicationContext(),"id : "+s, Toast.LENGTH_SHORT).show();
Notification notification = new Notification(R.drawable.icon_noti,message,new Date().getTime());
PendingIntent pI = PendingIntent.getActivity(getApplicationContext(), 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notification.setLatestEventInfo(getApplicationContext(), message, "Touch to remove" , pI);
notification.sound = soundUri;
notificationManager.notify(i,notification);
}
This happens because when you call
you provide a static request id with value “1”, so the method returns you the same
PendingIntentevery time. To create differentPendingIntentsfor every item, provide unique request ids’ for every call. Hope this helps.