android-architecture-components - 强制分页库数据源刷新

标签 android-architecture-components android-jetpack android-livedata android-paging android-architecture-lifecycle

在我的 ViewModel 中,我使用

加载数据
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()

效果很好。但是,当我的数据发生变化时,LiveData<PagedList<Notification>>没有得到通知。我能做些什么来触发 LiveData刷新(ViewModel 知道更改何时发生)。

最佳答案

您可以使用 DataSource 中的 invalidate() 方法触发数据更新。

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.

更多信息:Notify when data is invalid

关于android-architecture-components - 强制分页库数据源刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53172300/

相关文章:

android - WorkManager两次启动Worker

android - 支持 fragment 管理器 .replace() 和 ViewModel

android - 有时,ConflatedBroadcastChannel 会在没有任何操作的情况下触发最近的值

android - 导航拱组件 : Passing placeholder param for deeplink

android - 从 LiveData.observe() 添加项目到适配器的最佳实践

android - MutableLiveData<String> 到 MutableLiveData<Int>

android - MutableLiveData 未在 UI 中更新

Android分页边界回调说明

android - 具有多个顶级目的地的导航图

android - java/kotlin 模块中的 Jetpack Paging 3