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

作者:junjie 时间:2023-05-31 20:16:55 

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

猜你喜欢

  • 基于JWT.NET的使用(详解)

    2021-07-09 22:15:25
  • Spring框架通过工厂创建Bean的三种方式实现

    2022-11-23 11:29:54
  • Java删除二叉搜索树的任意元素的方法详解

    2021-10-04 12:27:26
  • Android仿微信Viewpager-Fragment惰性加载(lazy-loading)

    2023-12-16 23:50:59
  • Idea 搭建Spring源码环境的超详细教程

    2023-09-30 16:13:17
  • 关于Android中drawable必知的一些规则

    2021-08-26 16:24:41
  • OpenGL ES实现光照效果(六)

    2022-06-30 16:08:52
  • C#读取csv格式文件的方法

    2023-08-28 22:38:46
  • Spring5中的WebClient使用方法详解

    2023-08-05 14:50:24
  • SpringBoot中使用Servlet三大组件的方法(Servlet、Filter、Listener)

    2021-07-19 18:41:43
  • Java实现邮件找回密码功能

    2022-08-18 07:12:57
  • Android开发使用自定义View将圆角矩形绘制在Canvas上的方法

    2021-06-08 01:03:17
  • C/C++中比较字符串的方法详解

    2023-03-22 18:55:40
  • java实现简单的英文文本单词翻译器功能示例

    2023-11-28 10:22:15
  • java实现文件拷贝的七种方式

    2023-07-20 19:01:41
  • 快速学习C# 设计模式之职责链模式

    2022-03-28 17:47:45
  • java文件上传下载代码实例

    2023-11-10 05:06:14
  • C#使用opencv截取旋转矩形区域图像的实现示例

    2023-11-12 22:20:44
  • 关于Java的ArrayList数组自动扩容机制

    2021-11-26 13:12:46
  • Android编程开发ScrollView中ViewPager无法正常滑动问题解决方法

    2023-12-15 01:21:32
  • asp之家 软件编程 m.aspxhome.com