美文网首页
安卓paging库自定义datasource时千万不要在load

安卓paging库自定义datasource时千万不要在load

作者: vb12 | 来源:发表于2018-09-29 12:42 被阅读143次

如题.

我们可能之前习惯通过rxjava的方式请求网络数据了, 并在在onNext()方法中处理返回结果.
但是千万不要在自定的paging库中的几种DataSource类中这么做.
尤其是loadInitial(), 这并不单单是性能的问题, 而是可能无法正常显示得到的数据.

这里有一篇中文的流程分析, 里面也提到了这个问题, 但是我没看明白他说的原因.
https://ankko.github.io/2018/09/12/Android%E7%BB%84%E4%BB%B6Paging%E7%9A%84%E4%BD%BF%E7%94%A8%E5%8F%8A%E5%8E%9F%E7%90%86/

这里还有一篇英文的使用示例, 里面也提到了这个问题
https://medium.com/@Ahmed.AbdElmeged/android-paging-library-with-rxjava-and-rest-api-e5c229fd70ba

You maybe wonder why i don’t use one of Rx most powerful features which specify the threads i want to work in or observe on. I already try this but it give strange behavior after some analysis i realize that the load methods called on background thread provided by Paging. The problem is you get the data on thread and load methods called on another thread.

WTF!

相关文章

网友评论

      本文标题:安卓paging库自定义datasource时千万不要在load

      本文链接:https://www.haomeiwen.com/subject/hibvoftx.html