且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

加载在Android的外部数据的***方式

更新时间:2023-12-04 23:38:52

按照谷歌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