android-foreground-service

Community

Keep Android data collection alive reliably

Authordrewid74
Version1.0.0
Installs0

System Documentation

What problem does it solve?

Prevents Android foreground data collection services from failing during Activity lifecycle changes by ensuring correct Android 14 foregroundServiceType handling, immediate startForeground safety, null-intent resilience, and clean shutdown.

Core Features & Use Cases

  • Android 14+ foregroundServiceType compliance: Avoids runtime ForegroundServiceTypeNotAllowedException by matching manifest and startForeground type requirements for the service’s purpose (e.g., location, connectedDevice, camera, microphone, or combinations).
  • Lifecycle-safe long-running collection: Uses START_STICKY with a null-intent guard so process-death restarts stop cleanly instead of running in an invalid state.
  • Intent-based control + StateFlow status: Starts and stops work via Intent actions while exposing collection state through StateFlow so UI/ViewModel layers never hold hardware references.
  • Source-priority fallback: Supports internal sensor fallback when an external source (like BLE) is unavailable, keeping the recording pipeline functional.
  • Robust notification + shutdown: Creates the notification channel in Application, throttles notification updates, and flushes pending writes before stopping.

Quick Start

Implement a DataCollectionService foreground service that declares the correct foregroundServiceType in the manifest, calls startForegroundCompat as the first line of onStartCommand, and exposes CollectionStatus via StateFlow while controlling start/stop via Intent actions.

Dependency Matrix

Required Modules

None required

Components

Standard package

šŸ’» Claude Code Installation

Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.

Please help me install this Skill:
Name: android-foreground-service
Download link: https://github.com/drewid74/ai_skills/archive/main.zip#android-foreground-service

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.