简体   繁体   中英

Android notifications overlap each other

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.

在此处输入图片说明

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!!!

为时已晚,但解决方案是不创建NotificationCompat.Builder的新实例,在每次通知更新中使用相同的生成器,以避免动画重叠。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM