LoaderManager获取数据下线,然后在网上 [英] LoaderManager get data offline, then online

查看:143
本文介绍了LoaderManager获取数据下线,然后在网上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按照这个漂亮的可用性模式,其中应用程序商店的数据离线更快的响应和更新它时,它在网上获取新的数据。

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.

  1. 在应用程序上下文,而不是SQLite的存储数据
  2. 在两个独立的 AsyncTaskLoaders - offlineLoader onlineLoader 。第一取出从SQLite数据库中的数据,并立即显示它,如果它的存在,并从外部服务器的第二个加载数据,其写入数据库(用于offlineLoader)和替换离线数据
  1. Storing the data in the application context instead of SQLite
  2. Two separate AsyncTaskLoaders - offlineLoader and onlineLoader. 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 ContentProviders with Loaders loading data to the UI and Services 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆