Tash
05/25/2021, 11:45 PMsuspend
functions or collecting Flows
via lifecycleOwner
-> scope?Adam Powell
05/25/2021, 11:54 PMAdam Powell
05/25/2021, 11:54 PMTash
05/26/2021, 12:07 AMLifecycleObserver
would only be interested in the onCreate()
lifecycle method from which to launch coroutines? Otherwise, hooking into onStart()
etc seems awkward/redundantTash
05/26/2021, 12:10 AMLifecycleObserver
offers nice dependency inversion and direct access to the LifecycleOwner
, but I can imagine it’d be nice to be able to inject/provide via DI some scoped Lifecycle
for such “worker” classes that launch coroutines for specific/contained work. Not sure if that’s an anti-pattern, though 🤔Adam Powell
05/26/2021, 1:08 AMlifecycleScope
extension on LifecycleOwner is exactly that, it spans onCreate => onDestroy: https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#lifecyclescopeAdam Powell
05/26/2021, 1:09 AMrepeatOnLifecycle
runs one iteration of the given body block each time the lifecycle raises up to at least a given state, i.e. started: https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#repeatonlifecycleTash
05/26/2021, 3:22 AMLifecycle
is enough given all these extension functions that are available.Adam Powell
05/26/2021, 3:27 AM