anil90 anil90 - 3 years ago 445
Android Question

Rxjava2 flowable not firing onComplete

Here is the code

private fun setUpDistrictSpinner() {
.flatMap { list -> Flowable.fromIterable(list) }
.map { district ->
override fun onComplete() {
Timber.d("district List loaded total " + districtList.size)

override fun onError(t: Throwable?) {

override fun onNext(t: District) {

override fun onSubscribe(s: Subscription) {


onNext is firing but onComplete will not fire. There is also no error message. I am loading list of district into a spinner. Using Room database and Kotlin
This is where I get the Flowable

fun getAllDistricts(): Flowable<List<District>> {
Timber.d("District list accessed")
return appDatabase.districtDao().getAllDistricts()


Answer Source

The Flowable returned by Room never completes. It allows you to receive update upon database modifications.

Here’s how the Flowable behaves:

  1. When there is no user in the database and the query returns no rows, the Flowable will not emit, neither onNext, nor onError.
  2. When there is a user in the database, the Flowable will trigger onNext.
  3. Every time the user data is updated, the Flowable object will emit automatically, allowing you to update the UI based on the latest data.

If you want to receive onComplete event, switch to Maybe. You should read this article.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download