加载在Android的外部数据的最佳方式 [英] Best way to load external data in android

查看:120
本文介绍了加载在Android的外部数据的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是加载外部数据在Android的最佳方法是什么?

What is the best way to load external data in android?

目前,这是我做的:

  1. 创建REST风格的Web服务,它返回一个对象JSON数组(在服务器上)
  2. 在Android的调用HTTPGET和消费服务
  3. 通过解析响应JSON
  4. 使用GSON解析响应直入对象的数组
  5. 根据需要使用对象的数组

这是在Android文档?

Is this the optimal approach in terms of the Android documentation?

推荐答案

按照谷歌I / o创建REST应用 presentation,你应该做的是这样的:

According to the Google I/O Creating REST apps presentation, you should do something like:

  1. 创建返回JSON(或XML)RESTful Web服务
  2. 您的行为(通过AsyncTask的或装载机)请求的资源来自ContentProvider的
  3. 的ContentProvider返回包含它在一个本地SQLite分贝缓存数据的游标
  4. ContentProvider的询问服务(或SyncService)从Web服务收集新的数据
  5. 您的活动利用光标在UI显示数据
  6. 在服务调用HTTPGET
  7. 在服务解析响应
  8. 服务推新数据的ContentProvider(这反过来又更新sqlite的分贝)
  9. 的ContentProvider要求有NotifyChange通知应用程序没有在第3步
  10. 返回游标新数据
  11. 您的活动重新申请一个更新光标从ContentProvider的,然后更新UI新鲜的数据游标
  1. Create RESTful web service that returns JSON (or XML)
  2. Your activity (via AsyncTask or Loader) requests resources from a ContentProvider
  3. ContentProvider returns a Cursor containing the data it has cached in a local Sqlite Db
  4. ContentProvider asks a Service (or SyncService) to collect fresh data from the web service
  5. Your activity makes use of Cursor to display data in UI
  6. Service invokes HttpGet
  7. Services parses response
  8. Service pushes new data into ContentProvider (which in turn updates Sqlite db)
  9. ContentProvider calls notifyChange to inform app there is new data for Cursor returned in step 3
  10. Your activity re-requests an updated Cursor from ContentProvider, and then updates UI with fresh data in Cursor

这篇关于加载在Android的外部数据的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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