I'm aware it's a complex question that cannot have a definite answer without posting a few hundreds of lines of code, which is why I'm looking for help through general ideas and pointers.
I have a Room @Query
returning a RxJava3 Flowable<List<...>>
which I subscribe to on RxJava thread Schedulers.io()
, and observe from an activity-scoped ViewModel
on RxJava thread AndroidSchedulers.mainThread()
. The data is then stored in my ViewModel as LiveData
, which plays better than RxJava when it comes to handle Android components' lifecycle.
The idea is to have a clean and immediate data update pattern, not to have to handle disposal and re-subscription separately on each activity or fragment lifecycle event such as onPaused
and onResumed
, and being updated in the background even when my activity is hidden in order to avoid that awful refresh lag when returning to my activity. I was pretty amazed at that design pattern. I still am, but I'm beginning to have doubts.
When starting another activity with the same design pattern, I do change a value and immediately get an updated List<...>
from the other ViewModel
. Different Activity
, different ViewModel
, same design, same database table. When returning to the first Activity
, I find that the new data does never get updated: Room did not emit any update even though the data set has changed. I have to dispose and subscribe again in order to see the new data.
So my question is: any pointer on where the source of my problem might be?! Is there something rotten in the core of this design pattern? Something I misunderstood about all those things are supposed to work together? Is it just a mistake of mine due to some threading issue? Or should I fill a bug report for Room?
I tried to observe another non-Room RxJava3 observable from the ViewModel
of my first Activity
, and it does get updates when its data set is updated.
By the way, I also use Hilt in order to inject eveything as @Singleton
.
Thank you for your time :-)