欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android中通知栏跳动问题解决方法

程序员文章站 2024-03-30 21:57:39
曾经遇到过这样的问题,在我的代码中使用了通知栏,一切都正常,但是就是正在进行的通知栏中属于我的程序的那一条总是上下跳来跳去,一闪一闪的。感觉用户体验很不好,于是google...

曾经遇到过这样的问题,在我的代码中使用了通知栏,一切都正常,但是就是正在进行的通知栏中属于我的程序的那一条总是上下跳来跳去,一闪一闪的。感觉用户体验很不好,于是google一下,找到了解决方法。

在我的代码,我是这样写的。

复制代码 代码如下:

notification.when = system.currenttimemillis();

这就是问题的关键,对于通知来说,when这个属性值应该在activity一启动的时候就应该固定。如果没有固定,就会使用默认的值,默认的值就是当前的时间,即system.currenttimemillis()的值。因此使用一个自定义的固定值就可以解决问题。

复制代码 代码如下:

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

以下如google介绍如何使用notification的when的说明。

复制代码 代码如下:

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