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

 更新时间:2015年01月19日 08:57:08   投稿:junjie  
这篇文章主要介绍了Android中通知栏跳动问题解决方法,导致这个问题的原因是when这个属性值,默认它是使用的系统当前时间,这就是导致跳动问题的原因,指定一个固定时间即可解决这个问题,需要的朋友可以参考下

曾经遇到过这样的问题,在我的代码中使用了通知栏,一切都正常,但是就是正在进行的通知栏中属于我的程序的那一条总是上下跳来跳去,一闪一闪的。感觉用户体验很不好,于是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编程之短信窃听器实现方法

    这篇文章主要介绍了Android编程之短信窃听器实现方法,以实例形式较为详细的分析了Android编程实现窃听器的具体步骤与实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-11-11
  • Android实现环形进度条代码

    Android实现环形进度条代码

    这篇文章主要为大家详细介绍了Android实现环形进度条的代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-01-01
  • Android EditText实现输入表情

    Android EditText实现输入表情

    editText是TextView的子类,TextView能用的工具EditText都能用,接下来通过实例代码给大家分享Android EditText实现输入表情功能,感兴趣的朋友一起看看吧
    2017-08-08
  • Android Selector 按下修改背景和文本颜色的实现代码

    Android Selector 按下修改背景和文本颜色的实现代码

    这篇文章主要介绍了Android Selector 按下修改背景和文本颜色的实现代码,本文通过实例代码和demo展示给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-11-11
  • Android原生实现多线程断点下载实例代码

    Android原生实现多线程断点下载实例代码

    本篇文章主要介绍了Android原生实现多线程断点下载实例代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-05-05
  • Android对EditTex的图片实现监听

    Android对EditTex的图片实现监听

    这篇文章主要为大家详细介绍了Android如何对EditTex的图片实现监听,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-10-10
  • Android自定义圆形View实现小球跟随手指移动效果

    Android自定义圆形View实现小球跟随手指移动效果

    这篇文章主要为大家详细介绍了Android自定义圆形View实现小球跟随手指移动效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-03-03
  • Flutter自定义实现神奇动效的卡片切换视图的示例代码

    Flutter自定义实现神奇动效的卡片切换视图的示例代码

    这篇文章主要介绍了Flutter自定义实现神奇动效的卡片切换视图的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-04-04
  • Android编程实现微信分享信息的方法

    Android编程实现微信分享信息的方法

    这篇文章主要介绍了Android编程实现微信分享信息的方法,实例分析了Android官方demo示例,讲述了Android微信分享功能的具体实现技巧,需要的朋友可以参考下
    2015-10-10
  • Android自定义view实现侧滑栏详解

    Android自定义view实现侧滑栏详解

    之前一直没有写侧滑菜单的实现方法,今天计划补上。手机开发中,往往存在很多功能没处放的问题。我们可能会把功能放入一个菜单列表,但现在一种流行的做法是侧滑菜单
    2022-11-11

最新评论