0

I have implemented push notifications for my android app .I am able to show multiple notification in notification bar but only one notification work at a time.

i think the problem in flags type

Intent.FLAG_ACTIVITY_CLEAR_TOP
Intent.FLAG_ACTIVITY_SINGLE_TOP

and

PendingIntent.FLAG_CANCEL_CURRENT

this is my code , please tell me what type of Flag i will set

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent resultPendingIntent =
PendingIntent.getActivity(
   mContext,
   0,
   intent,
   PendingIntent.FLAG_CANCEL_CURRENT
);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

You need to take the different ID for each notification. as follows : (put different notification ID every time).

You can also create unique notification ID each time by following :

int notiID = (int) System.currentTimeMillis();

PendingIntent.getActivity(
   mContext,
   notiID, //notification ID
   intent,
   0
);

Thanks :)

Ankit Mehta
  • 4,251
  • 4
  • 19
  • 27
  • I'm trying: ` int NOTIFICATION_ID = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent resultPendingIntent = PendingIntent.getActivity( mContext, NOTIFICATION_ID, intent, 0 ); ` but all notification bar has clear – Salem Gauch Feb 07 '18 at 10:22
  • did you tried this code : int notiID = (int) System.currentTimeMillis(); ?? – Ankit Mehta Feb 07 '18 at 10:30
  • yes but all notifications bar has been closed, send me your email, can i send you my **NotificationUtils** Class – Salem Gauch Feb 07 '18 at 13:37