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