LoaderManager获取数据下线,然后在网上 [英] LoaderManager get data offline, then online
问题描述
我想按照这个漂亮的可用性模式,其中应用程序商店的数据离线更快的响应和更新它时,它在网上获取新的数据。
I would like to follow this nice usability pattern, where app stores data offline for faster response and updates it when it gets new data online.
和我用装载机
与 LoaderManager
。
现在,什么是实现与装载机
?
Now, what is the correct approach to implement the aforementioned approach with Loaders
?
目前我使用的两种方法,它有自己的缺点,一般来说,都不是很优雅的。
Currently I use two approaches, which have their downsides and, generally, are not very elegant.
- 在应用程序上下文,而不是SQLite的存储数据
- 在两个独立的
AsyncTaskLoaders
-offlineLoader
和onlineLoader
。第一取出从SQLite数据库中的数据,并立即显示它,如果它的存在,并从外部服务器的第二个加载数据,其写入数据库(用于offlineLoader)和替换离线数据
- Storing the data in the application context instead of SQLite
- Two separate
AsyncTaskLoaders
-offlineLoader
andonlineLoader
. The first fetches the data from SQLite database and shows it immediately if it's there and the second one loads the data from external server, writes it to database (for the offlineLoader) and replaces the offline data
我真的想拥有的是:
有一个单一的装载机其离线数据读取,并返回到LoaderManager,但随后继续工作,并返回新的在线数据时,它的准备。因此,它应该双倍返还? - 是它甚至有可能
A single Loader which fetches the data offline and returns it to LoaderManager, but continues to work afterwards and return the fresh online data when it's ready. So it should return twice - is it even possible?
推荐答案
该解决方案是使用的ContentProvider
s的装载机
■装载数据,用户界面和服务
取值下载数据,将其推到数据库中(并通知的ContentProvider
该应用程序的,剩下的,即它已经改变)。
The solution is to use ContentProvider
s with Loader
s loading data to the UI and Service
s downloading data and pushing it into the database (and notifying the ContentProvider
and the rest of the app, that it's been changed).
这篇关于LoaderManager获取数据下线,然后在网上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!