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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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!!!
回答2:
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.