Skip to content

Crash: streaming service does not call startForeground in time #186

Description

@zeevy

Crash reported in the Play Console after tapping Continue on the start streaming dialog:

android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException
Caused by android.app.StackTrace: Last startServiceCommon() call for this service was made here
  at android.content.ContextWrapper.startForegroundService
  at in.co.gorest.grblcontroller.ui.FileSenderTabFragment.lambda$startFileStreaming$4 (FileSenderTabFragment.java:199)

Cause

  • FileSenderTabFragment starts FileStreamerIntentService with startForegroundService(). Android then needs startForeground() within 10 seconds, and before the service stops.
  • The service calls startForeground() only deep in onHandleIntent, on the worker thread, after the setup. When no G-code file is found it returns early without calling it, the service stops, and Android kills the app. A worker thread that is busy or slow also misses the 10 seconds.

Fix

  • Call startForeground() first thing in onStartCommand, with the same notification (checking or streaming, and the file name), then hand the intent to IntentService.
  • Remove the two later startForeground() calls and their SDK_INT > N_MR1 checks, which are always true with minSdk 26.

Acceptance

  • Given the service starts with no file to stream, when it returns early, then the app does not crash, the "No gcode file selected" toast shows and the notification goes away.
  • The normal streaming and checking notifications look the same as before.

Activity

  1. zeevy commented on Oct 10, 2026

    @zeevy
    OwnerAuthor

    Fixed in PR #190 (branch fix/186-streaming-fgs-start-crash). Reproduced on the emulator with the old code and checked the fix there. Closes when the PR is merged.

  2. zeevy commented on Oct 10, 2026

    @zeevy
    OwnerAuthor

    The Android 10 RemoteServiceException from the Play Console (no message in the trace) is most likely the older form of this same crash. Its two known sources are this streaming start and the USB screen's startForegroundService() in onStart, which v2.61 already replaced (ed7501f). If the Play Console still shows it on v2.62 or later, it needs its message to look further.

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