开发者

Caching Objects parsed from XML in Android

开发者 https://www.devze.com 2023-02-16 10:51 出处:网络
I have an Android application which talks to a public Data-API by calling URLs. The API returns XML which describes search results or detailed Data of a particular dataset.

I have an Android application which talks to a public Data-API by calling URLs. The API returns XML which describes search results or detailed Data of a particular dataset.

In my Application i retrieve this data and parse it to Java Objects to display them in a ListView for example.

edit: Just to make it clearer: In my Application you can search for music Artists and get their whole discographic information. I Retrieve the list of Releases and display them in a ListView. (No problem right here, because the results of the same search request can change any minute i have to retrieve this data everytime a search request is issued).

Now i have a list with all the LPs the Beatles produced (for example). I can then click one particular LP and view the Details such as the Release Year and the Tracklist.

What i want to cache is the Details data and i'm currently thinking of which is开发者_如何学编程 the best way to do this. I thought of:

  • Retrieving the XML data once and store the XML Data in the SQLite Database (that would imply, that i have to parse the data everytime i want to access it again).
  • Retrieving the XML data once, parsing it once and somehow store the serialized JavaObject into the SQLite Database as ByteStream. (so all the time consuming work would be done just once).

What do you think is the best version or is there maybe another better way to achieve caching the results?


serializing an object would be quick solution but that could not be effective solution. Every a time you need to load entire object, while in this case if you are storing your data set into database then, using cursor/queries data handling will be smoother.

CursorAdapter will allow you to plug database cursor directly to list in GUI. I would suggest you to use database approach.

0

精彩评论

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

关注公众号