Android 服务完成时通知关闭
我正在创建一个通知,并在执行intent服务期间更新它。服务完成时会出现问题,通知也会取消Android 服务完成时通知关闭,android,service,android-notifications,android-intentservice,Android,Service,Android Notifications,Android Intentservice,我正在创建一个通知,并在执行intent服务期间更新它。服务完成时会出现问题,通知也会取消 intentNotification = new Intent(this, ScanProcessActivity.class); intentNotification.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); mNotificationManager = (Notificati
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());
在Intent服务完成后,我可以做些什么来保留通知
提前谢谢。我终于找到了解决办法 主要问题是我在使用:
startForeground(NOTIFICATION_ID, mBuilder.build());
这会导致意外行为,例如线程完成时取消通知
解决方案是将startForeground()调用更改为:
您是否使用NotificationManager来显示通知?是的,我正在使用NotificationManager来显示通知。
setAutoCancel(布尔自动取消)
添加到API级别11中,当用户触摸该通知时,该通知会自动取消。
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());