configure
Android entry point: builds the process-wide BackgroundTaskManager and installs it as BackgroundTaskManager.shared.
Normally you never call this. The library's manifest registers BackgrounderInitializer with androidx.startup, which calls it before Application.onCreate. Call it yourself only if your app removed the InitializationProvider, or if you need a BackgrounderEventListener or a pre-resolved WorkManager — in which case call it first thing in onCreate, before anything touches BackgroundTaskManager.shared.
Idempotent with the initializer: if an instance already exists and you pass no listener or WorkManager, the existing instance is returned (this is what lets multi-process apps call it unconditionally from onCreate). Passing either while an instance exists throws, because the live instance was built without them.
class MyApp : Application(), Configuration.Provider {
override fun onCreate() {
super.onCreate()
BackgroundTaskManager.shared.register(SyncWorker.ID) { SyncWorker(repo = …) }
BackgroundTaskManager.shared.start()
}
override val workManagerConfiguration: Configuration get() =
Configuration.Builder()
.setWorkerFactory(BackgroundTaskManager.shared.androidWorkerFactory())
.build()
}Plan §"DI-free initialization" §1.3 / §2.3 for the full sequencing argument and the Configuration.Provider chicken-and-egg note.
Parameters
your Application. The library uses it for getSharedPreferences, the ephemeral sweep, and (lazily) WorkManager.getInstance(application).
observability hook. Defaults to BackgrounderEventListener.Noop.
an optional pre-resolved WorkManager instance. Use this only if you have one already and want to skip the lazy WorkManager.getInstance(application) lookup. Most callers leave this null and let the library resolve via getInstance on first use.
Throws
if a BackgroundTaskManager is already live and a listener or WorkManager was passed.