我想在前台服务被销毁后删除通知。我尝试从
为什么这种方法不起作用?有没有办法在销毁服务时删除通知?
更新:当我玩弄通知时,我注意到了一件有趣的事情:
onDestroy()
和 unbind()
调用stopForeground(true)
。尽管 onUnbind() 和 onDestroy() 已被调用(我可以从日志中看到),但通知仍然存在。我通过从活动中调用 unbindService(playerConnection)
和 stopService(this)
来停止服务。为什么这种方法不起作用?有没有办法在销毁服务时删除通知?
更新:当我玩弄通知时,我注意到了一件有趣的事情:
fun hideNotification() {
stopForeground(true)
Log.d("PlayerService", "hideNotification")
}
当我按下按钮时,我会从我的活动中调用它。然后它会移除通知。但是当相同的函数从活动的onStop()或服务的onUnbind()或onDestroy()中调用时,它不起作用。我无法理解这些情况之间的区别。