Android Paging 3 how do we sync data in background?

Viewed 230

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.

1 Answers

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.

Related