Skip to content

Commit

Permalink
fix: Fix ForegroundService notification not auto-dismissing
Browse files Browse the repository at this point in the history
Always use startForeground, instead of notify,
even when updating the notification, to ensure
it gets automatically removed by the system when
the service stops.
  • Loading branch information
LouisCAD committed Mar 5, 2025
1 parent 402fb4e commit 65154a1
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/main/kotlin/com/infomaniak/core/ForegroundService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import splitties.intents.ServiceIntentSpec
import splitties.intents.intent
import splitties.mainhandler.mainHandler
import splitties.mainthread.isMainThread
import splitties.systemservices.notificationManager

/**
* Usage:
Expand Down Expand Up @@ -102,12 +101,7 @@ abstract class ForegroundService(
mainHandler.post { updateNotification(notification) }
return
}
if (foregroundStarted) {
notificationManager.notify(companion.notificationId, notification)
} else {
startForegroundWithType(companion.notificationId, notification)
foregroundStarted = true
}
startForegroundWithType(companion.notificationId, notification)
}

/**
Expand Down Expand Up @@ -164,7 +158,6 @@ abstract class ForegroundService(
isReDelivery = flags.hasFlag(START_FLAG_REDELIVERY)
)
startForegroundWithType(companion.notificationId, notification)
foregroundStarted = true
}
return if (redeliverIntentIfKilled) START_REDELIVER_INTENT else START_NOT_STICKY
}
Expand All @@ -175,6 +168,7 @@ abstract class ForegroundService(
} else {
startForeground(notificationId, notification)
}
foregroundStarted = true
}

final override fun onDestroy() {
Expand Down

0 comments on commit 65154a1

Please sign in to comment.