java - Android 通知相互重叠

标签 java android service notifications

我有两个服务,它们都彼此独立地创建通知。但是当我同时启动它们时,它们就像在为位置“战斗”(上下)。我希望有人知道如何解决它。谢谢。

enter image description here

最佳答案

我也遇到了类似的问题,尝试了各种方法。我最终能够使用共享首选项解决它。尽管这不是一种相对流行的方法,但它很有帮助,因为您可以跟踪发送的每个通知。这是一个代码 fragment :

SharedPreferences prefs = getSharedPreferences(Activity.class.getSimpleName(), Context.MODE_PRIVATE);
int notificationNumber = prefs.getInt("notificationNumber", 0);


notificationManager.notify(notificationNumber, notification);
SharedPreferences.Editor editor = prefs.edit();
notificationNumber++;
editor.putInt("notificationNumber", notificationNumber);
editor.commit();

我希望这会有所帮助..快乐编码!!!

关于java - Android 通知相互重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44675273/

相关文章:

Android Studio 将所有 aar 文件包含在一个目录中

android - React native expo - 响应超时

android - fragment 不启动服务

java - spring boot2.0中log4j2日志无法输出到文件中,谁能帮帮我?

java - 集成显卡上的 Java2D 绘图速度缓慢

android - 另一种类型的变量和动态值

linux - Prometheus 2.0 centos 服务无法启动,因为 "Opening storage failed", "permission denied"

c# - 单元测试,模拟 - 简单案例 : Service - Repository

java - nslookup 和 Java 的 InetAddress getHostName 之间的不同结果

java - 如何在这种情况下使用interrupt()