I want to remove a notification after my foreground service is being destroyed. I tried to call stopForeground(true)
from onDestroy()
and from unbind()
. Although onUnbind() and onDestroy() were called(I can see it from logs) notification is still there. I stop the service by calling unbindService(playerConnection)
and stopService(this)
from my activity.
Why it's not working this way? Any ideas on how to remove a notification when service is destroyed?
UPATE: one interesting thing I've noticed when playing around with the notification. I've made a special method inside the service:
fun hideNotification() {
stopForeground(true)
Log.d("PlayerService", "hideNotification")
}
Than I call it from my activity when the button is pressed. And it removes the notification. But the same function being called from activity's onStop() or service's onUnbind() or onDestroy() doesn't. I can't understand what the difference between these situations.