# Beginning RxKotlin · Observables and Subjects in Practice, Part 1 | raywenderlich.com

**URL:** <https://forums.kodeco.com/t/beginning-rxkotlin-observables-and-subjects-in-practice-part-1-raywenderlich-com/57644>\
**Category:** 🎓 Courses & Articles\
**Created:** [December 14, 2018, 7:13am UTC](https://forums.kodeco.com/t/beginning-rxkotlin-observables-and-subjects-in-practice-part-1-raywenderlich-com/57644 "2018-12-14T07:13:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![macsimus](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/macsimus/32/109104_2.png) [@macsimus](https://forums.kodeco.com/u/macsimus)\
**Post date:** [December 14, 2018, 7:13am UTC](https://forums.kodeco.com/t/beginning-rxkotlin-observables-and-subjects-in-practice-part-1-raywenderlich-com/57644/1 "2018-12-14T07:13:26Z")

</div>

* * *
This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/7419-beginning-rxkotlin/lessons/11](https://www.raywenderlich.com/7419-beginning-rxkotlin/lessons/11)

---

<div class="post-metadata">

**Author:** ![tomer](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tomer/32/99666_2.png) [@tomer](https://forums.kodeco.com/u/tomer)\
**Post date:** [July 18, 2019, 9:15am UTC](https://forums.kodeco.com/t/beginning-rxkotlin-observables-and-subjects-in-practice-part-1-raywenderlich-com/57644/2 "2019-07-18T09:15:25Z")

</div>

Hey, Joe.  
Thanks for the excellent course. really enjoying your courses.

my question:  
in the RxAndroid GitHub page:

> **[GitHub - ReactiveX/RxAndroid: RxJava bindings for Android](https://github.com/ReactiveX/RxAndroid)**
>
> RxJava bindings for Android. Contribute to ReactiveX/RxAndroid development by creating an account on GitHub.

they say:

```
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
// (see https://github.com/ReactiveX/RxJava/releases for latest 2.x.x version)
implementation 'io.reactivex.rxjava2:rxjava:2.x.x'

```

so should add 3 dependencies for kotlin like so?

```
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'

```

or perhaps the rxkotlin dependency is regularly maintained and already imports the latest version?

---

<div class="post-metadata">

**Author:** ![macsimus](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/macsimus/32/109104_2.png) [@macsimus](https://forums.kodeco.com/u/macsimus)\
**Post date:** [July 18, 2019, 4:53pm UTC](https://forums.kodeco.com/t/beginning-rxkotlin-observables-and-subjects-in-practice-part-1-raywenderlich-com/57644/3 "2019-07-18T16:53:11Z")

</div>

Hi @tomer thanks for the kind words!

On your question, there’s a similar comment on the RxKotlin page:

> The maintainers do not update the RxJava dependency version for every RxJava release, so you should explicitly add the desired RxJava dependency version to your pom.xml or build.gradle(.kts).

So yes it would be best to explicitly include the RxJava dependency in order to make sure you’re using the version you want. Just watch out for any inconsistencies between the wrapper and the main RxJava library, should they pop up.

Thanks again!

---

<div class="post-metadata">

**Author:** ![bkopiske](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bkopiske/32/102075_2.png) [@bkopiske](https://forums.kodeco.com/u/bkopiske)\
**Post date:** [February 18, 2022, 8:34am UTC](https://forums.kodeco.com/t/beginning-rxkotlin-observables-and-subjects-in-practice-part-1-raywenderlich-com/57644/4 "2022-02-18T08:34:56Z")

</div>

For anyone wondering: the example code uses an anti pattern by using mutable lists and updating them – you should use immutable ones. When you’re adjusting the sample that way, make sure to fix the infinite loop bug in the activity this change will unmask.

```kotlin
  private val imagesSubject: BehaviorSubject<List<Photo>>
      = BehaviorSubject.createDefault<List<Photo>>(listOf())

```

and

```kotlin
  fun addPhoto(photo: Photo) {
    val newValue = imagesSubject.value + photo
    imagesSubject.onNext(newValue)
  }

  fun clearPhotos() {
    imagesSubject.onNext(emptyList())
  }

```

Additionally the infinite loop in the Activity hides here:

```kotlin
    viewModel.getSelectedPhotos().observe(this, Observer { photos ->
      photos?.let {
        if (photos.isNotEmpty()) {
          val bitmaps = photos.map { BitmapFactory.decodeResource(resources, it.drawable) }
          val newBitmap = combineImages(bitmaps)
          collageImage.setImageDrawable(BitmapDrawable(resources, newBitmap))
        } else {
          actionClear()
        }
      }
    })

```

This is, because `actionClear()` tells the ViewModel to clear the elements again which ends up in a recursion.
