LifecycleDispose dispose RxJava streams on lifecycle down event that corresponding to Activity/Fragment's lifecycle state when subscribe using Android Architecture Components Lifecycle.
Dispose when onPause is called.
Observable.interval(1, TimeUnit.SECONDS)
.subscribe()
.disposeOnPause(this) // `this` is FragmentActivity or FragmentDispose when onStop is called.
Observable.interval(1, TimeUnit.SECONDS)
.subscribe()
.disposeOnStop(this) // `this` is FragmentActivity or FragmentDispose when onDestroy is called. If Fragment has view, dispose when onDestroyView is called.
Observable.interval(1, TimeUnit.SECONDS)
.subscribe()
.disposeOnDestroy(this) // `this` is FragmentActivity or FragmentDispose on lifecycle down event that corresponding to Activity/Fragment's lifecycle state. See next section.
Observable.interval(1, TimeUnit.SECONDS)
.subscribe()
.disposeOnLifecycle(this) // `this` is FragmentActivity or FragmentTable 1 Corresponding between Activity's lifecycle state and Lifecycle down event.
| Subscribe | Lifecycle.State | Lifecycle.Event | Dispose |
|---|---|---|---|
| onCreate | INITIALIZED | ON_DESTROY | onDestroy |
| onStart | CREATED | ON_STOP | onStop |
| onResume | STARTED | ON_PAUSE | onPause |
| onPause | STARTED | ON_DESTROY | onDestroy |
| onStop | CREATED | ON_DESTROY | onDestroy |
| onDestroy | DESTROYED | ON_DESTROY | onDestroy |
Table 2 Corresponding between Fragment's lifecycle state and Lifecycle down event.
| Subscribe | ViewLifecycle.State | Dispose | Lifecycle.State | Dispose |
|---|---|---|---|---|
| onAttach | IllegalStateException | onDestroy | INITIALIZED | onDestroy |
| onCreate | IllegalStateException | onDestroy | INITIALIZED | onDestroy |
| onCreateView | IllegalStateException | onDestroyView | CREATED | onDestroy |
| onViewCreated | INITIALIZED | onDestroyView | not called | not called |
| onStart | CREATED | onStop | CREATED | onStop |
| onResume | STARTED | onPause | STARTED | onPause |
| onPause | STARTED | onDestroyView | STARTED | onDestroy |
| onStop | CREATED | onDestroyView | CREATED | onDestroy |
| onDestroyView | DESTROYED | onDestroyView | not called | not called |
| onDestroy | IllegalStateException | onDestroy | DESTROYED | onDestroy |
repositories {
mavenCentral()
}
dependencies {
implementation 'com.wada811.lifecycledispose:lifecycledispose2:x.y.z'
}repositories {
mavenCentral()
}
dependencies {
implementation 'com.wada811.lifecycledispose:lifecycledispose3:x.y.z'
}Copyright (C) 2019 wada811
Licensed under the Apache License, Version 2.0