Skip to content

Android: AudioRecordingService stays in foreground after recording stops #474

Closed

Description

@abretonc7s

Summary

After stopRecording() completes normally on Android, AudioRecordingService remains isForeground=true with its ongoing notification. The phone keeps showing a recording notification even though no recording is in progress.

Reproduce

Pixel 6a, Android 17 (API 37), dev build.

Run any recording to completion, then:

adb -s <serial> shell dumpsys activity services net.siteed.audioplayground.development | grep -E 'ServiceRecord|isForeground'

Observed

ServiceRecord{... net.siteed.audiostudio.AudioRecordingService ...}
isForeground=true foregroundId=1 types=0x00000080
foregroundNoti=Notification(channel=recording_service ... flags=ONGOING_EVENT|NO_CLEAR|FOREGROUND_SERVICE)

JS reports isRecording: false at the same moment, so the two sides disagree: the JS session ended but the Android foreground service did not.

Expected

The service leaves the foreground and removes its notification once recording stops, so no ongoing recording notification remains.

Notes

Found while validating the benchmark script's teardown. Reproduces on a normal completed run, not only on interrupted ones, so it is independent of how the recording ends. Impact is a stale user-visible notification plus a foreground service held longer than needed.

Suspect the stop path does not call stopForeground/stopSelf on every branch. Not yet traced to a specific line.

Activity

  1. abretonc7s commented on Aug 22, 2026

    @abretonc7s
    CollaboratorAuthor

    Additional evidence: the stale notification is not backed by any capture.

    Immediately after a completed run, on a Pixel 6a:

    JS:            isRecording=false, durationMs=0
    Service:       isForeground=true
    Notification:  posted, flags=ONGOING_EVENT|NO_CLEAR|FOREGROUND_SERVICE (channel=recording_service)
    audio_flinger: Input device: 0 (AUDIO_DEVICE_NONE)  -- mic not in use
    

    So the three views disagree: the notification says recording, the service is still foreground, and the mic is idle. No audio is being captured. The record screen correctly shows no waveform, which is what makes it visible to a user: an ongoing recording notification while the app itself shows nothing recording.

    Confirms the notification is a leftover from a service that never left the foreground, not a live capture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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