Show notes
In this short fragment episode, Donn explains how you can clean up your RxJava 2 streams and ensure no memory leaks are occurring by using the AutoDispose library from Uber.
Shownotes
Code Samples
Java
myObservable .map(...) .as(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(this))) .subscribe(...)
Kotlin
myObservable .map(...) .autoDisposable(AndroidLifcycleScopeProvider.from(this)) .subscribe(...)
With Scope Event Provided
myObservable .map(...) .autoDisposable(AndroidLifcycleScopeProvider.from(this, Lifecycle.Event.ON_DESTROY)) .subscribe(...)
Testing
// File: CustomerService.ktclass CustomerService @Inject constructor(...) { lateinit var scopeProvider: ScopeProvider}// Usage in Fragment/Activity/etcval service = CustomerService(...).apply { scopeProvider = AndroidLifecycleScopeProvider.from(this)}// Usage in Testval service = CustomerService(...).apply { scopeProvider = TestScopeProvider.create()}
Contact
- @fragmentedcast or our Youtube channel
- @donnfelker and donnfelker (on Instagram)
- @kaushikgopal and kaushikgopal (on Instagram)
- Fragmented Chat