Package-level declarations
public interface LifecycleScopeProviderextends ScopeProvider {
Observable
A common use case for this is objects that have implicit lifecycles, such as Android's
Activity
, Fragment
, and View
classes. Internally at subscription-time, AutoDispose will resolve a io.reactivex.CompletableSource representation of the target end
event in the lifecycle, and exposes an API to dictate what corresponding events are for the current lifecycle state (e.g. ATTACH
->DETACH
). This also allows you to enforce lifecycle boundary requirements, and by default will error if the lifecycle has either not started yet or has already ended.
autodispose2.lifecycle.LifecycleScopeProvider is a special case targeted at binding to things with lifecycles. Its API is as follows: - lifecycle - returns an of lifecycle events. This should be backed by a or something similar (BehaviorRelay
, etc). - correspondingEvents - a mapping of events to corresponding ones, i.e. Attach -> Detach. - peekLifecycle - returns the current lifecycle state of the object.
In requestScope, the implementation expects to these pieces to construct a io.reactivex.CompletableSource representation of the proper end scope, while also doing precondition checks for lifecycle boundaries. If a lifecycle has not started, it will send you to onError
with a . If the lifecycle as ended, it is recommended to throw a autodispose2.lifecycle.LifecycleEndedException in your correspondingEvents() mapping, but it is up to the user.
To simplify implementations, there's an included utility class with factories for generating representations from instances.