I have develop an android app. this app generate notification and I have also to dismiss them and act when dismiss.
If I receive one notif and dismiss it, the intent is received. and it works if I receive one, dismiss, receive one, dismiss...
But in case I receive 5 notifications and start dismissing them, as soon as I dismiss the first one, the intent is received but never after, I
I was expected to be able to get 5 intents as 5 dismisses. In my case, the notification manager dismiss them but app only receive one.
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//aVariable = 0; // Do what you want here
mContext.unregisterReceiver(this);
if(intent.getAction().equals(NOTIFICATION_DELETED_ACTION)) {
mNotififDismissId = intent.getExtras().getInt("IdDismiss");
if(mNotififDismissId == globalTweetNotif)
cancelAll(context);
else
cancelNotification(context, mNotififDismissId);
}
}
};
When creating a new notif, I'm doing :
private void singleNotification() {
Intent resintent = new Intent(NOTIFICATION_DELETED_ACTION);
resintent.putExtra(rIdDismiss",mNotification.get(mNotification.size() - 1).mTwitterNotifId);
PendingIntent pendintIntent = PendingIntent.getBroadcast(mContext, 0, resintent, PendingIntent.FLAG_CANCEL_CURRENT);
mContext.registerReceiver(receiver, new IntentFilter(NOTIFICATION_DELETED_ACTION));
Notification notification = new Notification(android.R.drawable.btn_default,
mNotification.get(mNotification.size() - 1).mTwitterNotifTitle.toString(), System.currentTimeMillis());
Intent notificationIntent = new Intent(mContext, TwitterHomeActivity.class);
notificationIntent.putExtra("IS_NOTIFICATION", true);
notificationIntent.putExtra("Title", mContext.getResources().getString(R.string.app_name));
notificationIntent.putExtra("Text", mNotification.get(mNotification.size() - 1).mTwitterNotifText.toString());
notificationIntent.putExtra("Url", mNotification.get(mNotification.size() - 1).mTwitterImgUrl.toString());
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(mContext, mNotification.get(mNotification.size()-1).mTwitterNotifUniqueId, notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT);// );
notification.setLatestEventInfo(mContext,
mContext.getResources().getString(R.string.app_name),
mNotification.get(mNotification.size()-1).mTwitterNotifText.toString(),
contentIntent);
notification.contentIntent = contentIntent;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.deleteIntent = pendintIntent;
mNotificationManager.notify(mNotification.get(mNotification.size() - 1).mTwitterNotifId, notification);
}
The NotificationManager is got by:
mNotificationManager = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
The default behavior works fine, receive, dismiss,,, but I need to also be able to receive, receive, recieve, dismiss, dismiss, dismiss
Any Idea