0

我正在創建通知並在執行意向服務期間更新通知。服務完成時出現問題,通知也被取消。服務完成時關閉通知

intentNotification = new Intent(this, ScanProcessActivity.class); 
    intentNotification.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    mBuilder = new NotificationCompat.Builder(getApplicationContext()); 

    mBuilder.setSmallIcon(R.mipmap.ic_app) 
      .setAutoCancel(true) 
      .setOngoing(true) 
      .setContentTitle("Title") 
      .setContentText("text") 
      .setWhen(System.currentTimeMillis()); 

我能做些什麼的意圖服務完成後保存通知?

在此先感謝。

+0

你使用NotificationManager顯示通知? – 0X0nosugar

+0

是的,我正在使用通知管理器來顯示通知。 – MarcForn

+0

'setAutoCancel(boolean autoCancel)'在API級別11中添加使此通知在用戶觸摸時自動解除。 – pskink

回答

0

最後我找到了一個解決方案。

的主要問題是,我用:

startForeground(NOTIFICATION_ID, mBuilder.build()); 

這會導致意外的行爲,例如當線程完成取消通知。

解決的辦法是改變startForeground()調用:

mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());