Android 通知相互重叠 [英] Android notifications overlap each other

查看:34
本文介绍了Android 通知相互重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have two services who both create notifications independently from each other. But when I start them both, They are like "fighting"(go up and down) for the position. I hope anyone knows how to fix it. Thank you.

推荐答案

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

I had a similar problem and I tried all sorts of methods. I was eventually able to solve it using sharedpreferences. Although this isn't a relatively popular way of doing this, it helps because you can keep track of every notification sent. Here's a code snippet:

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();

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

I hope this helps.. Merry coding!!!

这篇关于Android 通知相互重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆