Android中通知栏跳动问题解决方法
曾经遇到过这样的问题,在我的代码中使用了通知栏,一切都正常,但是就是正在进行的通知栏中属于我的程序的那一条总是上下跳来跳去,一闪一闪的。感觉用户体验很不好,于是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
推荐阅读
-
Android中通知栏跳动问题解决方法
-
Android中Fragment多层嵌套时onActivityResult无法正确回调问题的解决方法
-
Android中Fragment多层嵌套时onActivityResult无法正确回调问题的解决方法
-
Android App中ViewPager所带来的滑动冲突问题解决方法
-
Android App中ViewPager所带来的滑动冲突问题解决方法
-
Android Drawerlayout侧拉栏事件传递问题的解决方法
-
Android Drawerlayout侧拉栏事件传递问题的解决方法
-
Android中Fragment管理及重叠问题的解决方法
-
Android中利用NetworkInfo判断网络状态时出现空指针(NullPointerException)问题的解决方法
-
Android中Fragment管理及重叠问题的解决方法