Noby
Noby

Reputation: 6602

how to avoid clear notifications when activity finishes

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....!

Upvotes: 4

Views: 769

Answers (3)

John
John

Reputation: 371

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

       android:launchMode="singleTask"
       android:taskAffinity=""
       android:excludeFromRecents="true"

Upvotes: 3

Robert Estivill
Robert Estivill

Reputation: 12497

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

Upvotes: 0

Joe Malin
Joe Malin

Reputation: 8641

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.

Upvotes: 0

Related Questions