Hi, I am having diffulty understanding why I canno...
# room
t
Hi, I am having diffulty understanding why I cannot retrieve the most upto date data from my room database when using paging3 library
my use case is as follows:- The user clicks on a list item that triggers a remote api call. on successful completion of this api call my local database will be updated and I am expecting my list item to be updated to reflect the data has indeed been updated. heres some psuedo code that illustrates how I am implementing this ViewModel Code =============
val outcome: Flow<Outcome> = service.myRemoteAPIcall(arg1 , arg2)
val result: Flow<PagingData<MyDataUI>> = myDatabase.fetchLocalData()
Fragment Code ============
viewLifecycleOwner.lifecycleScope.launch {
outcome.take(1).collect { outcome ->
if (outocme == Success)
withContext(Dispatchers.Main) {
result.collect {
myDataAdapter.submitData(it)
}
}
}
}
I do not collect the
PagingData
flow until the remote api call has completed successfully. Therefore I would expect the data that is submitted to my
PagingDataAdapter
to reflect the changes made by the remote api call. However this is not the case. i would like to understand two aspects of the observed behaviour. i). why am i not seeing the updated data? where do I make my mistake. ii).how can I fix this? how do i "wait" correctly for the remote api to complete before fetching the local (updated) data?
y
so your
myRemoteAPIcall
finishes writing into the database before it returns ?
if so, this should not happen
unless paging is cached and was accessed before
t
thanks for looking at my issue, yes the remote api call finishes writing before it returns however the paging was accessed before to display the original data