ForegroundService class

Constructors

ForegroundService()

Properties

hashCode int
The hash code for this object.
read-onlyinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

isBackgroundIsolate Future<bool>
read-only
isIsolateCommunicationSetup bool
read-only
notification ForegroundServiceNotification
set notification text, etc. through methods on this property
final

Static Methods

foregroundServiceIsStarted() Future<bool>
getContinueRunningAfterAppKilled() Future<bool>
only works with v2 Android embedding (Flutter 1.12.x+) gets whether the foreground service should continue running after the app is killed for instance when it's swiped off of the recent apps list default behavior is true = keep service running after app killed
getServiceFunction() Future<Function>
get the function being executed periodically by the service
getServiceFunctionAsync() Future<bool>
see setServiceFunctionAsync
getServiceIntervalSeconds() Future<int>
get the execution period for the service function (get/setServiceFunction); period is "minimum/best-effort" - will try to space executions with an interval that's at least this long
getWakeLock() Future<void>
tells the foreground service to also hold a wake lock
isBackgroundIsolateSetupComplete() Future<bool>
if coordinating communication between foreground service function and main isolate, can use this to confirm setup complete before sending any messages
releaseWakeLock() Future<void>
tells the foreground service to release the wake lock, if it's holding one
sendToPort(dynamic message) Future<void>
sends a message to the other isolate, which is handled by whatever function was passed to setupIsolateCommunication in that isolate
setContinueRunningAfterAppKilled(bool shouldContinueRunning) Future<void>
only works with v2 Android embedding (Flutter 1.12.x+) sets whether the foreground service should continue running after the app is killed for instance when it's swiped off of the recent apps list default behavior = true = keep service running after app killed
setServiceFunction(Function serviceFunction) Future<void>
set the function being executed periodically by the service
setServiceFunctionAsync(bool isServiceFunctionAsync) Future<void>
by default, the service function is async, and will be invoked on a timer if you want to wait for the previous function execution to finish before invoking it again, set this to false (default is true) it will also wait until the serviceInterval has elapsed ex: interval = 5 seconds; instance1 required execution time = 9 seconds; instance2 required execution time = 2 seconds
setServiceIntervalSeconds(int intervalSeconds) Future<void>
set the execution period for the service function (get/setServiceFunction) period is "minimum/best-effort" - will try to space executions with an interval that's at least this long
setupIsolateCommunication(dynamic messageHandler(dynamic message)) Future<void>
when sendToPort(message) is called in one isolate, messageHandler(message) will be invoked from the other isolate i.e. main_sendToPort -> background_messageHandler and vice-versa
startForegroundService([Function serviceFunction, bool holdWakeLock = false]) Future<void>
serviceFunction needs to be self-contained i.e. all setup/init/etc. needs to be done entirely within serviceFunction since apparently due to how the implementation works callback is done within a new isolate, so memory is not shared (static variables will not have the same values, etc. etc.) communication of simple values between serviceFunction and the main app can be accomplished using setupIsolateCommunication & sendToPort
stopForegroundService() Future<void>