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.
Crash reported in the Play Console after tapping Continue on the start streaming dialog:
Cause
FileSenderTabFragmentstartsFileStreamerIntentServicewithstartForegroundService(). Android then needsstartForeground()within 10 seconds, and before the service stops.startForeground()only deep inonHandleIntent, 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
startForeground()first thing inonStartCommand, with the same notification (checking or streaming, and the file name), then hand the intent toIntentService.startForeground()calls and theirSDK_INT > N_MR1checks, which are always true with minSdk 26.Acceptance