Skip to content

[Bug]: Fatal Exception: android.app.ForegroundServiceDidNotStartInTimeException #526

Open

Description

@christian-apollo

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

We get those crashes time to time:

Fatal Exception: android.app.ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{808d146 u0 com.apolloscooters/com.google.android.libraries.geo.navcore.service.base.NavigationService}
       at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2078)
       at android.app.ActivityThread.access$2800(ActivityThread.java:259)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2303)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:233)
       at android.os.Looper.loop(Looper.java:344)
       at android.app.ActivityThread.main(ActivityThread.java:8249)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:589)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1071)

also:

          Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{883ead4 u0 com.apolloscooters/com.google.android.libraries.geo.navcore.service.base.NavigationService c:com.apolloscooters}
       at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2675)
       at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2643)
       at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException()
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:3068)
       at android.os.Handler.dispatchMessage(Handler.java:110)
       at android.os.Looper.loopOnce(Looper.java:273)
       at android.os.Looper.loop(Looper.java:363)
       at android.app.ActivityThread.main(ActivityThread.java:10060)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

React Native version

0.81.5

React version

19.1.0

Package version

0.12.1

Native SDK versions

  • I haven't changed the version of the native SDKs

React Native Doctor Output

✓ Node.js - Required to execute JavaScript code
✓ yarn - Required to install NPM dependencies
✓ Watchman - Used for watching changes in the filesystem when in development mode
✓ Metro - Required for bundling the JavaScript code

Android
✓ Adb - Required to verify if the android device is attached correctly
✓ JDK - Required to compile Java code
✓ Android Studio - Required for building and installing your app on Android
✓ ANDROID_HOME - Environment variable that points to your Android SDK installation
✓ Gradlew - Build tool required for Android builds
✖ Android SDK - Required for building and installing your app on Android

  • Versions found: N/A
  • Version supported: 36.0.0

iOS
✓ Xcode - Required for building and installing your app on iOS
✓ Ruby - Required for installing iOS dependencies
✓ CocoaPods - Required for installing iOS dependencies
✓ .xcode.env - File to customize Xcode environment

Errors: 1
Warnings: 0

Steps to reproduce

I didn't manage to reproduce yet, but it might be related to the fact that we cleanup the navigation controller when the app goes in background.

Expected vs Actual Behavior

No crash...

Code Sample

// Example code here

Additional Context

No response

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    triage meI really want to be triaged.
    on Jan 10, 2026
  2. added
    priority: p0Highest priority. Critical issue. P0 implies highest priority.
    and removed
    triage meI really want to be triaged.
    on Jan 15, 2026
  3. illuminati1911 commented on Mar 17, 2026

    @illuminati1911
    Contributor

    Hey @christian-apollo and thank you for opening the ticket (sorry for the delay in responding).

    Could you please try with the latest version of the SDK? We have made significant changes to the architecture and other things between the current version 0.14.2 and the version you experienced the issue with. 0.12.1.

  4. christian-apollo commented on Mar 19, 2026

    @christian-apollo
    ContributorAuthor

    Hey @illuminati1911 I updated to 0.14.2 and it is still happening:

              Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{2e97f14 u0 com.apolloscooters/com.google.android.libraries.geo.navcore.service.base.NavigationService c:com.apolloscooters}
           at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2553)
           at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2521)
           at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException()
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2905)
           at android.os.Handler.dispatchMessageImpl(Handler.java:142)
           at android.os.Handler.dispatchMessage(Handler.java:125)
           at android.os.Looper.loopOnce(Looper.java:269)
           at android.os.Looper.loop(Looper.java:367)
           at android.app.ActivityThread.main(ActivityThread.java:9333)
           at java.lang.reflect.Method.invoke(Method.java)
           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:566)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
    

    It happens a few seconds (or less) after the app is moved to the background, around 1% of the time.

    When the app goes in the background, we cleanup the navigation controller (to stop using the GPS, is there an alternative?), So I assume that there's a concurrency issue. It is probably also related to the Android Map SDK, I will report it upstream.

    const cleanup = () => {
          if (listenersAddedRef.current) {
            removeAllListeners();
            listenersAddedRef.current = false;
          }
          useNavigationStore.setState({isNavigationInitialized: false, isNavigating: false});
          setGlobalNavigationController(null);
          navigationController?.cleanup().catch(error => {
            console.error('Navigation cleanup failed', error);
          });
        };
    
  5. christian-apollo commented on Mar 21, 2026

    @christian-apollo
    ContributorAuthor

    I'm seeing a crash that occurred 30 seconds after the cleanup finished, so maybe something wasn't fully cleaned up.

  6. christian-apollo commented on Apr 3, 2026

    @christian-apollo
    ContributorAuthor

    I confirm that by calling stopUpdatingLocation() instead of cleanup, it fixes the crash.

  7. illuminati1911 commented on May 26, 2026

    @illuminati1911
    Contributor

    Hey @christian-apollo.

    As you can see here we have merged a fix that might help with this. Could you try on a latest SDK version if you still run into this issue?

  8. christian-apollo commented on Jun 6, 2026

    @christian-apollo
    ContributorAuthor

    It is hard to tell if is related to the cleanup but this crash is still happening for us. It was still happening (but les often) when we stopped calling cleanup. Now i put back the cleanup, I will see if it is happening more, but it is still happening:

    Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{cfc2f06 u0 com.apolloscooters/com.google.android.libraries.geo.navcore.service.base.NavigationService c:com.apolloscooters}
           at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2553)
           at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2521)
           at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException()
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2905)
           at android.os.Handler.dispatchMessageImpl(Handler.java:142)
           at android.os.Handler.dispatchMessage(Handler.java:125)
           at android.os.Looper.loopOnce(Looper.java:269)
           at android.os.Looper.loop(Looper.java:367)
           at android.app.ActivityThread.main(ActivityThread.java:9333)
           at java.lang.reflect.Method.invoke(Method.java)
           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:566)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
    
    Caused by android.app.StackTrace: Last startServiceCommon() call for this service was made here
           at android.app.ContextImpl.startServiceCommon(ContextImpl.java:2126)
           at android.app.ContextImpl.startForegroundService(ContextImpl.java:2080)
           at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:875)
           at com.google.android.libraries.geo.navcore.service.base.ad.f(PG:3)
           at com.google.android.libraries.geo.navcore.service.base.ad.e(PG:1)
           at com.google.android.libraries.geo.navcore.service.base.ad.a(PG:1)
           at com.google.android.libraries.geo.navcore.service.base.s.h(PG:8)
           at com.google.android.libraries.geo.navcore.service.base.s.a(PG:1)
           at com.google.android.libraries.geo.navcore.service.base.m.call(m.java:1)
           at com.google.android.libraries.navigation.internal.yy.g.b(PG:5)
           at com.google.android.libraries.geo.navcore.service.base.n.a(PG:2)
           at com.google.android.libraries.navigation.internal.yc.a.i(PG:4)
           at com.google.android.libraries.navigation.internal.yc.a.h(PG:1)
           at com.google.android.libraries.navigation.internal.yc.a.f(PG:1)
           at com.google.android.libraries.navigation.internal.yc.d.b(PG:3)
           at com.google.android.libraries.navigation.internal.aav.jo.addLocationListener(PG:11)
           at com.google.android.react.navsdk.NavModule.registerLocationListener(NavModule.java:1125)
           at com.google.android.react.navsdk.NavModule.onHostResume(NavModule.java:1201)
           at com.facebook.react.bridge.ReactContext.onHostResume(ReactContext.java:255)
           at com.facebook.react.runtime.ReactLifecycleStateManager.moveToOnHostResume(ReactLifecycleStateManager.java:38)
           at com.facebook.react.runtime.ReactHostImpl.onHostResume(ReactHostImpl.kt:257)
           at com.facebook.react.runtime.ReactHostImpl.onHostResume(ReactHostImpl.kt:246)
           at com.facebook.react.ReactDelegate.onHostResume(ReactDelegate.java:130)
           at com.facebook.react.ReactActivityDelegate.onResume(ReactActivityDelegate.java:200)
           at expo.modules.ReactActivityDelegateWrapper$onResume$1.invokeSuspend(ReactActivityDelegateWrapper.kt:177)
           at expo.modules.ReactActivityDelegateWrapper$onResume$1.invoke(ReactActivityDelegateWrapper.kt:2)
           at expo.modules.ReactActivityDelegateWrapper$onResume$1.invoke(ReactActivityDelegateWrapper.kt:1)
           at expo.modules.ReactActivityDelegateWrapper$launchLifecycleScopeWithLock$1.invokeSuspend(ReactActivityDelegateWrapper.kt:452)
           at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
           at kotlinx.coroutines.internal.DispatchedContinuation.resumeUndispatchedWith$kotlinx_coroutines_core(DispatchedContinuation.java:237)
           at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:278)
           at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
           at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:358)
           at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:134)
           at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:53)
           at kotlinx.coroutines.BuildersKt.launch(Builders.kt:1)
           at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:44)
           at kotlinx.coroutines.BuildersKt.launch$default(Builders.kt:1)
           at expo.modules.ReactActivityDelegateWrapper.launchLifecycleScopeWithLock(ReactActivityDelegateWrapper.kt:450)
           at expo.modules.ReactActivityDelegateWrapper.launchLifecycleScopeWithLock$default(ReactActivityDelegateWrapper.kt:446)
           at expo.modules.ReactActivityDelegateWrapper.onResume(ReactActivityDelegateWrapper.kt:175)
           at com.facebook.react.ReactActivity.onResume(ReactActivity.java:76)
           at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1739)
           at android.app.Activity.performResume(Activity.java:9450)
           at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5898)
           at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5941)
           at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:73)
           at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:63)
           at android.app.servertransaction.TransactionExecutor.executeLifecycleItem(TransactionExecutor.java:169)
           at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:101)
           at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2987)
           at android.os.Handler.dispatchMessageImpl(Handler.java:142)
           at android.os.Handler.dispatchMessage(Handler.java:125)
           at android.os.Looper.loopOnce(Looper.java:269)
           at android.os.Looper.loop(Looper.java:367)
           at android.app.ActivityThread.main(ActivityThread.java:9333)
           at java.lang.reflect.Method.invoke(Method.java)
           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:566)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority: p0Highest priority. Critical issue. P0 implies highest priority.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ Proxy