Skip to content

Android docs: Clarify the usage of startForegroundService() #2479

Open
@Levi-Lesches

Description

@Levi-Lesches

The docs for startForegroundService() seems to be inaccurate in a few ways:

  1. 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 its onBind() just returns null.

  2. 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)

  3. The docs claim to support any startType, but the plugin doesn't actually handle cases other than START_NOT_STICKY (see [flutter_local_notifications] Fix crashes related to Android foreground service start type #2475)

  4. 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.

  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions