Android notifications overlap each other

2019-08-02 16:38发布

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.

enter image description here

2条回答
家丑人穷心不美
2楼-- · 2019-08-02 17:02

Too late but the solution is to not create a new instance of NotificationCompat.Builder, use the same builder in every updates of your notification to avoid overlapping animation.

查看更多
我命由我不由天
3楼-- · 2019-08-02 17:20

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

查看更多
登录 后发表回答