Skip to content

Refactor app to use Foreground Service (Android) with startForeground #26

@paulpv

Description

@paulpv

Overview

Refactor the Android application to run core operations in a Foreground Service, started using startForeground. This is required for proper background execution in modern versions of Android and must use an appropriate Foreground Service Type.

Requirements

  • Migrate the relevant background operation(s) to a new or existing Service implementation, started/stopped using Context.startForegroundService() and startForeground().
  • Properly select and implement a Foreground Service Type (e.g., SPECIAL_USE, MICROPHONE, or REMOTE_MESSAGING depending on your need). The corresponding permission must be added to the AndroidManifest.
  • Update AndroidManifest.xml:
    • Define the <service> with the correct android:foregroundServiceType.
    • Add <uses-permission android:name="android.permission.FOREGROUND_SERVICE_*" /> for the chosen type.
  • Implement notification handling for the foreground service (persistent notification, channels, etc.).
  • Ensure correct handling of lifecycle events and sticky service logic as shown in the referenced demo code.
  • Document in code (and/or README) why the chosen Foreground Service Type and implementation approach were selected, particularly if using SPECIAL_USE.

Guides & references:

Acceptance Criteria

  • App reliably runs core background logic in a properly configured Foreground Service
  • Permissions, service type, and notification meet Android 13+ requirements, minimizing risk of crash due to permission or timing (race condition) issues
  • Thorough in-code comments and a summary of design decisions are present

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions