ForegroundServiceHandler class
Properties
-
hashCode
→ int
-
The hash code for this object.
no setterinherited
-
runtimeType
→ Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(Invocation invocation)
→ dynamic
-
Invoked when a nonexistent method or property is accessed.
inherited
-
toString()
→ String
-
A string representation of this object.
inherited
Static Methods
-
foregroundServiceIsStarted()
→ Future<bool>
-
-
getContinueRunningAfterAppKilled()
→ Future<bool>
-
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, i.e keeping the service running after the app is
killed.
-
getServiceFunction()
→ Future<Function?>
-
The function being executed periodically by the service
-
getServiceFunctionAsync()
→ Future<bool>
-
-
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>
-
-
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>
-
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.
only works with v2 Android embedding (Flutter 1.12.x+)
-
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>
-
-
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>
-