Skip to content

Fatal Exception: java.lang.IllegalStateException - Not allowed to start service Intent (app is in background) #321

Open
@ReneFerrari

Description

@ReneFerrari

DFU Bootloader version (please complete the following information):

  • SDK version: 31
  • Library version: 1.12.0

Device information (please complete the following information):

  • Device: Any device running Android 8 or higher

Describe the bug
From time to time we are facing this crash (Android 8 and up due to changes with services). Basically the App is in background and tries to start a service.

The affected LOC is: no.nordicsemi.android.dfu.DfuBaseService.onHandleIntent (DfuBaseService.java:1413)

(Note: It crashes on all startService calls, so not only the one I picked here)

I think changing it to:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    startForegroundService(intent);
} else {
    startService(intent);
}

would probably solve it.

Is there anything speaking against it?

I just checked for Android 12 and up there are unfortunately more restrictions: https://developer.android.com/about/versions/12/behavior-changes-12#foreground-service-launch-restrictions
So startForegroundService won't work there, rather WorkManager should be used

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions