开发者

Best way to load external data in android

What is the best way开发者_C百科 to load external data in android?

Currently, this is what I do:

  1. Create RESTful web service that returns a JSON Array of objects (on a server)
  2. In android invoke HTTPGet and consume service
  3. Parse through response JSON
  4. Use GSON to parse response straight into an array of objects
  5. Use the array of objects as needed

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


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

  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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜