Fragmented - Android Developer Podcast

147: Disposing RxJava 2 Streams with AutoDispose


Listen Later

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
  • AutoDispose Library
  • Tool to help migrate to RxJava 2
  • CatchUp Library
    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
    • @fragmentedcast or our Youtube channel
    • @donnfelker and donnfelker (on Instagram)
    • @kaushikgopal and kaushikgopal (on Instagram)
    • Fragmented Chat
    • ...more
      View all episodesView all episodes
      Download on the App Store

      Fragmented - Android Developer PodcastBy Donn Felker, Kaushik Gopal

      • 5
      • 5
      • 5
      • 5
      • 5

      5

      68 ratings


      More shows like Fragmented - Android Developer Podcast

      View all
      Design Details by Brian Lovin, Marshall Bock

      Design Details

      361 Listeners

      Developer Tea by Jonathan Cutrell

      Developer Tea

      402 Listeners

      Does Not Compute by Sean Washington, Rockwell Schrock

      Does Not Compute

      53 Listeners

      Toolsday by Una Kravets, Chris Dhanaraj

      Toolsday

      48 Listeners

      Swift Unwrapped by JP Simard, Jesse Squires, Spec Network, Inc.

      Swift Unwrapped

      90 Listeners