isForegroundStartAllowed

fun isForegroundStartAllowed(trigger: ServiceStartTrigger, appInForeground: Boolean, sdkInt: Int = Build.VERSION.SDK_INT): Boolean(source)

Returns true when Context.startForegroundService() is expected to succeed for trigger.

Returning false is not a failure to recover from — it means the platform would reject the start, so the app must not make the call at all. The service is picked up by the next legitimate trigger, which in practice is the user opening the app (ServiceStartTrigger.UserInterface).

Parameters

appInForeground

whether this process currently holds a user-visible component.

sdkInt

the running platform API level.