Solution to the notification bar run out problem in Android

  • 2020-06-12 10:34:51
  • OfStack

I've had a problem with the notification bar in my code, and it works fine, but the one that belongs to my program is always jumping up and down. The user experience was not good, so Google1 found a solution.

In my code, Here's how I wrote it.


notification.when = System.currentTimeMillis();

This is the crux of the matter. For notifications, the value of the when property should be fixed when activity1 is started. If it is not fixed, the default value is used, which is the current time, the value of System.currentTimeMillis (). Therefore, using a custom fixed value can solve the problem.


final long TIMESTAMP_FIXED = 1234567890l;
notification.when = TIMESTAMP_FIXED;

The following instructions, such as Google, show how to use when of notification.


A timestamp related to this notification, in milliseconds since the epoch. Default value: Now. Choose a timestamp that will be most relevant to the user. For most finite events, this corresponds to the time the event happened (or will happen, in the case of events that have yet to occur but about which the user is being informed). Indefinite events should be timestamped according to when the activity began. Some examples: Notification of a new chat message should be stamped when the message was received.
Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.
Notification of a completed file download should be stamped when the download finished.
Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).
Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
Notification of an ongoing countdown timer should be stamped with the timer's end time.

Reference

http://developer.android.com/reference/android/app/Notification.html#when


Related articles: