Reactive Programming with RxAndroid in Kotlin: An Introduction | raywenderlich.com

Learn about how Reactive programming is a whole new paradigm using RxJava and RxAndroid in Android with Kotlin.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2071847-reactive-programming-with-rxandroid-in-kotlin-an-introduction

You can use doFinally to dismiss the progress dialog, it is called if an item is emitted or on error.

This is a really good tutorial to finally get one’s head around Rx.

I found a problem in the section for Maybe
https://www.raywenderlich.com/2071847-reactive-programming-with-rxandroid-in-kotlin-an-introduction#toc-anchor-016

In the example, the last few lines look like this:

.subscribeOn(AndroidSchedulers.mainThread())
.subscribe {
   holder.itemView.imageFavorite.isChecked = it == 1 // 6
}

This causes an error:
io.reactivex.exceptions.OnErrorNotImplementedException: Only the original thread that created a view hierarchy can touch its views.

I think you want it to use observeOn, like this:

.observeOn(AndroidSchedulers.mainThread())
.subscribe {
  holder.itemView.imageFavorite.isChecked = it == 1
}

@kandroidj Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hello! Thank you for this tutorial, it is a great way to get started with reactive programming :slight_smile:

I found an issue on the section “Observe Button Clicks”. Here, we end with the app running database queries on the UI thread (which is what you intend). However, Android API 28 throws an IllegalStateException and does not let you execute the query at all (the app crashes when you press the button).
A quick fix for this (before you show us how to use threading on the next section) is adding the modifying the code for building the database instance:

INSTANCE = Room.databaseBuilder(context,
CheeseDatabase::class.java, “cheese.db”).allowMainThreadQueries()
.build()

This allows you to see the progress so far.

1 Like

@rva5120 Thank you for sharing your solution - much appreciated! :]

I am getting ‘Gradle project sync failed’ error after downloading ‘’ cheesefinder-starter" project. Cause of error is ‘org/gradle/internal/impldep/com/google/common/collect/Lists’. Anybody can help me to solve this issue?

@kandroidj Do you have any feedback about this? Thank you - much appreciated! :]

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!