Dispose automatically RxJava2 streams using AAC Lifecycle.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
gradle/wrapper
lifecycledisposable
lifecycledisposablesupport
.gitignore
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

LifecycleDisposable

Build Status

LifecycleDisposable dispose RxJava streams on lifecycle down event that corresponding to Activity/Fragment's lifecycle state when subscribe using Android Architecture Components Lifecycle.

Lifecycle State

Usage

Activity

class MainActivity : FragmentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        Observable.just("LifecycleDisposable")
            .subscribe()
            .disposeOnLifecycle(this) // dispose when onDestroy is called
    }
}

Table 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

Fragment

class MainFragment : Fragment() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        Observable.just("LifecycleDisposable")
            .subscribe()
            .disposeOnLifecycle(this) // dispose when onDestroy is called
    }
}

Table 2 Corresponding between Fragment's lifecycle state and Lifecycle down event.

Subscribe Lifecycle.State Lifecycle.Event Dispose
onCreate INITIALIZED ON_DESTROY onDestroy
onCreateView INITIALIZED ON_DESTROY onDestroyView
onStart CREATED ON_STOP onStop
onResume STARTED ON_PAUSE onPause
onPause STARTED ON_DESTROY onDestroyView
onStop CREATED ON_DESTROY onDestroyView
onDestroyView DESTROYED ON_DESTROY onDestroyView
onDestroy DESTROYED ON_DESTROY onDestroy

Gradle

repositories {
    maven { url "https://jitpack.io" }
}

AndroidX

dependencies {
    implementation 'com.github.wada811.LifecycleDisposable:lifecycledisposable:x.y.z'
}

Support Library

dependencies {
    implementation 'com.github.wada811.LifecycleDisposable:lifecycledisposablesupport:x.y.z'
}

License

Copyright (C) 2019 wada811

Licensed under the Apache License, Version 2.0