[英]Paging Library Invalidate Data Source
What's the simplest way to invalidate data retrieved by the paging library? 使分页库检索的数据无效的最简单方法是什么? I need to do that on logout. 我需要在注销时这样做。 I've a DataSource.Factory and a DataSource that extends PageKeyedDataSource. 我有一个DataSource.Factory和一个扩展PageKeyedDataSource的DataSource。 Is it a good idea to call invalidate() on DataSource contructor? 在DataSource构造函数上调用invalidate()是一个好主意吗? Will it work as expected? 它会按预期工作吗?
Assuming you are using the Paging library with other Architecture Components, such as LiveData
and LifecycleOwner
and your screen is closed on logout, the DataSource
will be invalidated automatically. 假设您将Paging库与其他架构组件(例如LiveData
和LifecycleOwner
并且您的屏幕在注销时关闭,则DataSource
将自动失效。
If you don't, you still can invalidate it manually, calling 如果没有,您仍然可以手动使其无效,请致电
yourDataSource.invalidate();
After the invalidation, you won't be able to continue using the DataSource
. 无效后,您将无法继续使用DataSource
。 However, the views from the adapter will not be detached automatically, so if you want to clear them, you should either provide from your DataSource.Factory
a DataSource
that will return no data either just clear the RecyclerView.Adapter
manually. 但是,适配器的视图不会自动分离,因此,如果要清除它们,则应该从DataSource.Factory
提供一个不返回任何数据的DataSource
,或者只是手动清除RecyclerView.Adapter
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.