registerBackgroundHandler method

Future<void> registerBackgroundHandler(
  1. BackgroundHandler handler
)

Registers handler to receive events when no UI is running, for example after the OS restarted the app in the background.

handler must be a top-level or static function annotated with @pragma('vm:entry-point'). It runs in a separate isolate without UI; it cannot share memory with the UI isolate. Call this on every app start, because callback handles can change when the app is updated.

If handler returns a future, the plugin waits for it before handling the next batch. Keep the work short: iOS gives a background app only a few seconds per Bluetooth event.

The returned future completes with an ArgumentError when handler is a closure or instance method.

Implementation

Future<void> registerBackgroundHandler(BackgroundHandler handler) =>
    _platform.registerBackgroundHandler(handler);