Hi all! [SOLVED] We are having a problem with Room...
# room
j
Hi all! [SOLVED] We are having a problem with Room database that returns a flow (that is converted to LiveData in ViewModel layer) not notifying DB changes. LiveData Observer-query is being fired from an APP process, but database insertions are fired by another process. Is this an expected behaviour? We can see data in the query table, but for some reason, LiveData update it is not being triggered. If we manually add data from the APP process, LiveData gets triggered. Any idea? Thank you!
m
AFAIR it works only in the same process, it’s just an adapter like in Rx. @Florina mentioned it in some blog post
🙌 1
j
Thank you for answering @Marcin Środa. I will try to Google about @Florina Room posts to see if I can find confirmation.
m
Can’t find Florina post, but Ray described it here: https://www.raywenderlich.com/9799571-kotlin-flow-for-android-getting-started#toc-anchor-012
In the current implementation, only the user can trigger data fetching. But you can easily implement logic that schedules and updates the database every three hours, for example. By doing this, you make sure your UI is up to date with the latest data. You'll use Kotlin Flow to get notified of every change in the table.
To understand it you can take a look at generated files (check for insert method f.e.)
j
Well, I've found here some possible solution: https://developer.android.com/training/data-storage/room/index.html
Check the note at the end of the page
We are going to give that a try and see what happens. Will post here the result
But thanks again for your help @Marcin Środa
m
Didn’t know about it. Nice one! 🙂
😊 1
j
So it is working now!
👍 1
my team was able to make it work following that note