Mark
02/03/2021, 10:57 AMFlow
. However, I prefer to work directly with the support library APIs. How to convert a generic query to a Flow
(either using a 3rd party library or building from scratch)?Mark Murphy
02/03/2021, 1:49 PMFlow
could be crazy complicated, as it implies initial results + results over time. Room as a metric ton of code around its InvalidationTracker
for trying to pull that off. My guess is that the Room team would steer you towards @RawQuery
.
If you are simply looking for asynchronous queries, putting your SupportSQLiteDatabase
call in a suspend
function, with your rawQuery()
(or whatever) wrapped in withContext(<http://Dispatchers.IO|Dispatchers.IO>)
probably suffices.Mark
02/03/2021, 1:57 PMContentProvider.notifyChange()
Mark Murphy
02/03/2021, 2:19 PMContentProvider
is coming from. Regardless, if you want to go through the headache of ensuring that you emit updates manually, then you could try a SharedFlow
both as a return value from your function and to hold onto in your repository (or whatever is doing the SQL calls). The repository would then need smarts in all of its other CRUD functions that if it is doing something that affects the results of your Flow
-based query, you execute some code that fires a fresh query result into that SharedFlow
.
To be honest, I'm not really certain what this is buying you over @RawQuery
, though.Mark
02/03/2021, 2:27 PMFlow
Ian Lake
02/03/2021, 3:16 PMMark
02/03/2021, 3:17 PM