diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt b/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt index 587a0160..cabea3aa 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt @@ -62,11 +62,9 @@ object ServiceNotification { } } fun stopForeground(service: Service) = synchronized(this) { - deviceCountsMap.remove(service) - if (deviceCountsMap.isEmpty()) service.stopForeground(true) else { - service.stopForeground(false) - manager.notify(NOTIFICATION_ID, buildNotification(service)) - } + val shutdown = deviceCountsMap.remove(service) != null && deviceCountsMap.isEmpty() + service.stopForeground(shutdown) + if (shutdown) manager.cancel(NOTIFICATION_ID) else manager.notify(NOTIFICATION_ID, buildNotification(service)) } fun updateNotificationChannels() {