Please login or sign up to post and edit reviews.
147: Disposing RxJava 2 Streams with AutoDispose
Publisher |
Spec
Media Type |
audio
Categories Via RSS |
Education
Technology
Publication Date |
Dec 31, 2018
Episode Duration |
00:15:22

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.kt
class CustomerService @Inject constructor(...) {
	lateinit var scopeProvider: ScopeProvider
}

// Usage in Fragment/Activity/etc
val service = CustomerService(...).apply {
	scopeProvider = AndroidLifecycleScopeProvider.from(this)
}

// Usage in Test
val service = CustomerService(...).apply {
	scopeProvider = TestScopeProvider.create()
}

Contact

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.

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.kt
class CustomerService @Inject constructor(...) {
	lateinit var scopeProvider: ScopeProvider
}

// Usage in Fragment/Activity/etc
val service = CustomerService(...).apply {
	scopeProvider = AndroidLifecycleScopeProvider.from(this)
}

// Usage in Test
val service = CustomerService(...).apply {
	scopeProvider = TestScopeProvider.create()
}

Contact

This episode currently has no reviews.

Submit Review
This episode could use a review!

This episode could use a review! Have anything to say about it? Share your thoughts using the button below.

Submit Review