BackgrounderEventListener

Optional lifecycle hook for app-level metrics — the imperative, callback-shaped delivery channel for the four v1 events (onScheduled / onStarted / onCompleted / onCancelled).

Kermit handles structured logging by default. This interface surfaces the same events for "is iOS actually running my tasks?" dashboards. Implementations must not block or throw — they're called inline on the dispatcher running the worker.

Prefer BackgroundTaskManager.events for new code. The SharedFlow<MonitorEvent> exposed there carries the same four events plus the richer events the listener does not cover (deferral, skip, attempt failure cause, retry scheduling, library error, schedule replacement). Both channels are fed by a single internal emit point (see MonitorEventEmitter) so the listener and the flow stay in lockstep.

Pass an implementation to the per-platform BackgroundTaskManager.create(...) factory; the default is Noop.

@OptIn(ExperimentalObjCName::class): Swift-rename annotation so callbacks read like Swift selectors at the iOS / macOS boundary (CLAUDE.md §8).

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
@ObjCName(swiftName = "onCancelled")
abstract fun onCancelled(taskId: String)

Called when Scheduler.cancel or Scheduler.cancelAll removes this task.

Link copied to clipboard
@ObjCName(swiftName = "onCompleted")
abstract fun onCompleted(taskId: String, attempt: Int, result: WorkResult)

Called when BackgroundWorker.execute returns (regardless of WorkResult).

Link copied to clipboard
@ObjCName(swiftName = "onScheduled")
abstract fun onScheduled(taskId: String, request: WorkRequest)

Called immediately after Scheduler.schedule accepts a WorkRequest.

Link copied to clipboard
@ObjCName(swiftName = "onStarted")
abstract fun onStarted(taskId: String, attempt: Int)

Called when the platform fires the worker and execution is about to begin.