register

open override fun register(lifecycle: Lifecycle, runWhileStopped: Boolean, callback: InputCallback<I>): CallbackToken<I, Unit>

Registers callback paired with lifecycle to be invoked later, and releases them when lifecycle is DESTROYED.

callback can be invoked when appropriate, given that an InputCallbackToken corresponding to the one returned is provided on invoke.

It respects the lifecycle of other app components, such as activities, fragments, or services. This ensures callback is only invoked when lifecycle is in an active state, unless runWhileStopped is passed as true, in which case it is invoked at any state until DESTROYED.

lifecycle is considered to be active when in the STARTED or RESUMED state.

Return

An InputCallbackToken that identifies callback by it's origin, allowing it to be retrieved and invoked later.

Parameters

lifecycle

The Lifecycle which callback will be paired to.

runWhileStopped

Indicates to invoke callback even when lifecycle is not active.

callback

The callback to be registered. Will be released when lifecycle be destroyed. May be invoked only when lifecycle is in an active state, or in whatever state until lifecycle be destroyed, according to runWhileStopped's value.