我正致力于在我的应用程序中创建第二个服务,由于它的工作与第一个完全不同,我希望他们发送单独的、不相关的通知。但是,第二个通知似乎取代了我状态栏中的第一个。
这是我的第一个服务的通知代码,看起来运行良好:
private void showNotification()
{
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder (this)
.setAutoCancel (true)
.setSmallIcon (R.drawable.icon)
.setWhen (System.currentTimeMillis())
.setContentTitle ("TCP Server Service Started");
TaskStackBuilder stackBuilder = TaskStackBuilder.create (this);
stackBuilder.addNextIntent (new Intent (this, Launcher.class)); // This cannot be removed
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent (0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent (resultPendingIntent);
notificationMngr.notify (0, mBuilder.build());
}
我基本上是将那个字符提取为字符并将其粘贴到我的新服务类中。这些魔法零(在 getPendingIntent() 和 notify() 中)参数中的任何一个我应该尝试将它们分开吗?
最佳答案
来自文档。
If the ID remains unchanged, the existing notification is updated.
那里也有一个很好的例子。检查here .查找更新通知。
关于android - 尝试在我的应用程序中创建两个服务并从每个服务发送通知,但第二个替换了第一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31060320/