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开发环境时出现eclipse获取不到ADT的解决方法

    配置android开发环境时出现eclipse获取不到ADT的解决方法

    这篇文章主要介绍了配置android开发环境时出现eclipse获取不到ADT的解决方法,涉及针对开发环境hosts文件域名映射的修改及eclipse配置的修改技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-12-12
  • Flutter折叠控件使用方法详解

    Flutter折叠控件使用方法详解

    这篇文章主要为大家详细介绍了Flutter折叠控件的使用方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-01-01
  • Android实现EditText换行自动缩进功能

    Android实现EditText换行自动缩进功能

    在很多需要输入多行文本的应用(如记事本、编程代码编辑器、博客编辑器等)中,自动缩进功能能大大提升用户的编辑效率与体验,本文给大家介绍了Android实现EditText换行自动缩进功能,下面提供整合后的完整代码示例,需要的朋友可以参考下
    2025-04-04
  • Android实现动态定值范围效果的控件

    Android实现动态定值范围效果的控件

    这篇文中给大家分享一个Android的控件,这个控件实现是一个可以动态选择定值范围的效果,实现后的效果很不错,对大家日常开发或许有所帮助,感兴趣的朋友们可以一起来看看。
    2016-09-09
  • 深入理解Android中的xmlns:tools属性

    深入理解Android中的xmlns:tools属性

    关于xmlns:tools属性的介绍网上有很多,小编觉得有必要整理一篇介绍较为详细的内容给大家,下面这篇文章就很深入的介绍了关于Android中的xmlns:tools属性,有需要的朋友们可以参考借鉴,下面来一起看看吧。
    2016-12-12
  • Android获取当前位置的经纬度数据

    Android获取当前位置的经纬度数据

    这篇文章主要介绍了Android获取当前位置的经纬度数据的相关资料,需要的朋友可以参考下
    2016-02-02
  • AndroidStudio3.6的卸载安装,Gradle持续下载/Gradle Build失败等问题

    AndroidStudio3.6的卸载安装,Gradle持续下载/Gradle Build失败等问题

    这篇文章主要介绍了AndroidStudio3.6的卸载安装,Gradle持续下载/Gradle Build失败等问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-03-03
  • Android实现EditText中添加和删除bitmap的方法

    Android实现EditText中添加和删除bitmap的方法

    这篇文章主要介绍了Android实现EditText中添加和删除bitmap的方法,实例分析了Android中EditText控件的bitmap操作技巧,需要的朋友可以参考下
    2016-01-01
  • Android实现文字动态高亮读取进度效果

    Android实现文字动态高亮读取进度效果

    这篇文章主要为大家详细介绍了Android实现文字动态高亮读取进度效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-05-05
  • Android开发笔记 TableLayout常用的属性介绍

    Android开发笔记 TableLayout常用的属性介绍

    今天看了安卓简单控件的布局方式,大概有绝对、相对、表格、线性、帧式布局五种方式,表格布局里面的一些属性相对来说比较复杂,下面主要谈谈表格方式布局的一些属性
    2012-11-11

最新评论