Pin Notification to top of notification area

There is a solution that does exactly what you want.

In the Notification class, there is a public field called when. According to the API:

The timestamp for the notification. The icons and expanded views are sorted by this key.

The default behaviour (for code and coders alike :) is to give when the timestamp of the notification:

notification.when = System.currentTimeMillis();

So - in order to maintain the correct order of notifications, all you need to do is give it a preset timestamp instead:

notification.when = previousTimestamp;

When you do this with all of your notifications, they maintain their order. I had the same problem as you and solved it this way.


You shouldn't keep sending the notification. Just use the ongoing event flag, like you already have in your code. Other notifications may come in and obscure yours, but that's just the way Android works.