Android 停止前台行为和通知

Android 停止前台行为和通知,android,android-service,Android,Android Service,我有一个intentService,在onHandleIntent()中,我在方法的开头调用startForeground(),在方法的结尾调用stopfrospect。当我调用stopForeground(false)时,即使我指定保留通知,通知也会被删除。文件说: 如果在服务仍在前台运行时停止服务,则通知也将被删除 因此,当intentService出于某种原因调用stopSelf()时,该服务似乎再次处于前台状态。正确行为的唯一方法是在stopForeground(true)之后创建新通知

我有一个
intentService
,在
onHandleIntent()
中,我在方法的开头调用
startForeground()
,在方法的结尾调用
stopfrospect
。当我调用
stopForeground(false)
时,即使我指定保留通知,通知也会被删除。文件说:

如果在服务仍在前台运行时停止服务,则通知也将被删除


因此,当
intentService
出于某种原因调用
stopSelf()
时,该服务似乎再次处于前台状态。正确行为的唯一方法是在
stopForeground(true)
之后创建新通知。我遗漏了什么吗?

OnHandleContent
中完成工作时,一个
IntentService
会自动停止。如果
IntentService
已停止,为什么要继续显示通知?听起来您应该使用常规的
服务
,在这里您可以控制对
stopSelf
的调用


无论您是否调用
stopForeground
,都可以通过调用
stopSelf
自动删除通知。服务已完成。

因为通知包含结果,如果不删除,这是一件好事。正如我所说,我在onHandleIntent结束前调用stopforeground。此外,您的评论没有任何意义,因为如果我在stopforeground之后(然后在stopSelf()之前)发布通知,它会起作用。