Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing Paging Library DataSource refresh

In my ViewModel, I load data using

private val pagingConfig = PagedList.Config.Builder()
    .setEnablePlaceholders(false)
    .setInitialLoadSizeHint(INITIAL_LOAD_SIZE_HINT)
    .setPageSize(PAGE_SIZE)
    .build()

val notificationList = LivePagedListBuilder<Long, Notification>(dataSourceFactory, pagingConfig).build()

Which works fine. However, when my data changes, LiveData<PagedList<Notification>> does not get notified. Is there anything I can do to trigger LiveData refresh (the ViewModel knows when the change occurs).

like image 844
liminal Avatar asked Dec 11 '25 15:12

liminal


1 Answers

You can trigger data update using invalidate() method from the DataSource.

When using the Paging Library, it's up to the data layer to notify the other layers of your app when a table or row has become stale. To do so, call invalidate() from the DataSource class that you've chosen for your app.

More information: Notify when data is invalid

like image 181
Alexey Denysenko Avatar answered Dec 13 '25 14:12

Alexey Denysenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!