2

As per This Android Sample using Paging-3 with RemoteMediator load function only triggers when then is no more data available, but in Realtime use-cases most of the time list might be updated. So how can we sync that data in background as well as show instant data which is available in DB and later show synced data. As per this sample it will never sync new data until refresh event occurs.

Abhishek Singh
  • 9,008
  • 5
  • 28
  • 53

1 Answers1

0

You can use the onBindViewHolder adapter method as a signal that your view just got bound to the screen and might be shown to the user, thus, making a request to update that specific item. This approach might also spam your webservice, so be careful.

A diferent approach is to upon the "refresh" signal from Paging 3, delete all items from database at the RemoteMediator and start fetching the pages from the network again.

João Paulo Sena
  • 665
  • 4
  • 11
  • you did no understand my problem i dont want to delete any item from date I just want to update them. Even if i cached 10 pages those 10 pages should show instantly as well as sync database from network – Abhishek Singh Mar 14 '21 at 22:26
  • That's why I gave you the first alternative, to use onBindViewHolder to update the item shown at the UI. But you should also implement some delay between same requests, so your webservice doesn't get flooded with requests. – João Paulo Sena Mar 15 '21 at 13:48
  • But what I understood from your question is that you want to update the items when they are shown to the user. Am I mistaken? – João Paulo Sena Mar 15 '21 at 13:58
  • Hmm. I just wan to sync that item from server. because Items deatils changes everyday – Abhishek Singh Mar 16 '21 at 07:12