簡體   English   中英

Android通知彼此重疊

[英]Android notifications overlap each other

我有兩個服務,它們都彼此獨立創建通知。 但是當我同時啟動它們時, 它們就像是為該位置“戰斗”(上下) 我希望任何人都知道如何解決它。 謝謝。

在此處輸入圖片說明

我遇到了類似的問題,嘗試了各種方法。 我最終能夠使用sharedpreferences解決它。 盡管這不是一種相對流行的方法,但它很有幫助,因為您可以跟蹤發送的每個通知。 這是一個代碼片段:

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

希望對您有所幫助。

為時已晚,但解決方案是不創建NotificationCompat.Builder的新實例,在每次通知更新中使用相同的生成器,以避免動畫重疊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM