4

I am posting different notifications to the notification bar.

All are having different id's but the intent is targeting same activity.

When I clicked on first notification the activity started and on clicking its finishing.

When my activity getting finished all remaining notifications in the bar are disappearing.

I want them to stay on the notification bar.

How to achive this.

here is the code.

     mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                        int id = 10;
                        notificationIntent = new Intent(context, MyAct.class); // creating intent.
                        notificationIntent.putExtra("data", data);
                        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);         

                        // defining actions while notification.
                        contentIntent = PendingIntent.getActivity(context, id,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);               
                        notification = new Notification(R.drawable.icon, message,
                                System.currentTimeMillis());
                        notification.setLatestEventInfo(context, "Hello", message,
                                contentIntent);

                        notification.defaults |= Notification.DEFAULT_VIBRATE;
                        notification.defaults |= Notification.DEFAULT_LIGHTS;
                        notification.defaults |= Notification.DEFAULT_SOUND;
                        mNotificationManager.notify(id, notification);
                        id++;

Thanks in advance....!

Noby
  • 6,562
  • 9
  • 40
  • 63

3 Answers3

3

You need to add following attributes to that activity in the manifest file.

       android:launchMode="singleTask"
       android:taskAffinity=""
       android:excludeFromRecents="true"
John
  • 361
  • 1
  • 11
0

Sounds like you created the notifications incorrectly. I suggest you re-read the javadoc for the Notification.Builder class to see what you've done wrong. You may have neglected to call setAutoCancel(), or you re-used the same object to post notifications.

Joe Malin
  • 8,621
  • 1
  • 23
  • 18
0

You can try with the ongoing flag http://developer.android.com/reference/android/app/Notification.html#FLAG_ONGOING_EVENT or adding the notification back in the status bar on the method onNewIntent of the activity

Robert Estivill
  • 12,369
  • 8
  • 43
  • 64