簡體   English   中英

嘗試在我的應用程序中創建兩個服務並從每個服務發送通知,但是第二個服務取代了第一個

[英]Trying to Create Two services in my application and send notifications from each, but the 2nd one replaces the 1st

我正在努力在應用程序中創建第二個服務,由於它的工作與第一個完全不同,因此我希望他們發送單獨的,不相關的通知。 但是,第二條通知似乎正在替換我狀態欄中的第一條通知。

這是我的第一個服務的通知代碼,似乎運行良好:

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()中)中的一個,我應該嘗試將其分開嗎?

從文檔中。

如果該ID保持不變,則更新現有通知。

那里也有一個很好的例子。 在這里檢查。 查找更新通知。

暫無
暫無

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

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