Description
The docs for startForegroundService()
seems to be inaccurate in a few ways:
-
The plugin does technically start a foreground service, but not in the normal way. A normal foreground service is associated with some work, like downloads, media playback, etc. In this plugin, the foreground service exits immediately after being created: its
onStartCommand()
returns after creating a notification, and itsonBind()
just returns null. -
The docs say to call the function multiple times to update the notification, but the standard way to update a foreground service notification is to call
show()
with the same ID (see Feature request: Adding a way to update sticky notification text without stopping and restarting that notification #2407) -
The docs claim to support any
startType
, but the plugin doesn't actually handle cases other thanSTART_NOT_STICKY
(see [flutter_local_notifications] Fix crashes related to Android foreground service start type #2475) -
The docs claim the notification will not be dismissible, but since API 33 (the plugin only supports 34+), foreground service notifications are dismissable by default.
-
The docs for the function show a lot of Android-specific setup. They could instead link to the setup steps of the README (see also [flutter_local_notifications] Refactor the README into platform-specific guides #2477)
But most importantly, when combining points 1 and 3, I've come to realize that this function does not actually start a "real" foreground service. It shows the notification, yes, but the point of a foreground service is to promote some logic-heavy code to the foreground to prevent it from being background by the system. As far as I can tell, this plugin isn't doing that, and in my opinion, that would be out-of-scope and better left to a plugin like flutter_foreground_service
or flutter_foreground_task
.
It seems from this SO answer that even if a service does no work, the whole app is elevated to foreground status. This clarifies why the Java code isn't doing anything interesting, and why the Dart function doesn't take a callback to run, like the other plugins I linked do.
@EPNW-Eric, what are your thoughts? If you want to add these to your PR, that would be great, otherwise I can do them after yours is merged.