Skip to content

[BUG] android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground #288

@adriankoczen

Description

@adriankoczen

Environment

  • expo-audio-studio version: 2.18.1
  • Expo SDK version: 53.0.20
  • Platform & OS version: Android 15 | Android 14
  • Device: SM-S906B | Redmi 14C

Description

Can this issue be reproduced in the AudioPlayground app?

  • Yes, on all platforms (Web, iOS, Android)
  • Yes, but only on specific platforms (please specify):
  • No, it only happens in my app

Is the behavior consistent across platforms?

  • Yes, the issue occurs the same way on all platforms I tested
  • No, the behavior differs between platforms

Only Android is affected.

Configuration

const config: RecordingConfig = {
  enableProcessing: true,
  sampleRate: 44100,
  intervalAnalysis: 200,
  channels: 1,
  encoding: "pcm_16bit"
};

Actual Behavior

The app crashes while recording, mostly after about 20 seconds.

Your app just crashed. See the error below.
android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{4bccc2 u0 com.xxx.xxx/net.siteed.audiostream.AudioRecordingService}
  android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2289)
  android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2260)
  android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:2554)
  android.os.Handler.dispatchMessage(Handler.java:106)
  android.os.Looper.loopOnce(Looper.java:222)
  android.os.Looper.loop(Looper.java:314)
  android.app.ActivityThread.main(ActivityThread.java:8779)
  java.lang.reflect.Method.invoke(Native Method)
  com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:569)
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1090)
Caused by android.app.StackTrace: Last startServiceCommon() call for this service was made here
  android.app.ContextImpl.startServiceCommon(ContextImpl.java:1963)
  android.app.ContextImpl.startForegroundService(ContextImpl.java:1917)
  android.content.ContextWrapper.startForegroundService(ContextWrapper.java:841)
  android.content.ContextWrapper.startForegroundService(ContextWrapper.java:841)
  net.siteed.audiostream.AudioRecordingService$Companion.startService(AudioRecordingService.kt:144)
  net.siteed.audiostream.AudioRecorderManager.startRecordingProcess(AudioRecorderManager.kt:924)
  net.siteed.audiostream.AudioRecorderManager.startRecording(AudioRecorderManager.kt:565)
  net.siteed.audiostream.ExpoAudioStreamModule$definition$lambda$34$$inlined$AsyncFunctionWithPromise$8.invoke(ObjectDefinitionBuilder.kt:619)
  net.siteed.audiostream.ExpoAudioStreamModule$definition$lambda$34$$inlined$AsyncFunctionWithPromise$8.invoke(ObjectDefinitionBuilder.kt:275)
  expo.modules.kotlin.functions.AsyncFunctionWithPromiseComponent.callUserImplementation$expo_modules_core_debug(AsyncFunctionWithPromiseComponent.kt:13)
  expo.modules.kotlin.functions.AsyncFunctionComponent.attachToJSObject$lambda$4$lambda$3(AsyncFunctionComponent.kt:45)
  expo.modules.kotlin.functions.AsyncFunctionComponent.$r8$lambda$WBsHNNTUGQ79nimAri8an_duSjI(Unknown Source:0)
  expo.modules.kotlin.functions.AsyncFunctionComponent$$ExternalSyntheticLambda1.invoke(D8$$SyntheticClass:0)
  expo.modules.kotlin.functions.AsyncFunctionComponent$dispatchOnQueue$1.invokeSuspend(AsyncFunctionComponent.kt:64)
  kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
  android.os.Handler.handleCallback(Handler.java:958)
  android.os.Handler.dispatchMessage(Handler.java:99)
  android.os.Looper.loopOnce(Looper.java:222)
  android.os.Looper.loop(Looper.java:314)
  android.os.HandlerThread.run(HandlerThread.java:67)

Additional context

I want to disable background audio because the Play Store requires additional declarations. If the plugin has default values, the app doesn't crash.

[
    "@siteed/expo-audio-studio",
    {
      "enableBackgroundAudio": false
    }
]

Checklist

  • I have updated to the latest version of expo-audio-studio
  • I have checked the documentation
  • I have tested in the official AudioPlayground app
  • I have verified microphone permissions are properly set up
  • I have filled out all required fields in this template

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