I have a list view contains 100+ rows. every time the user opens the app it load all the data from http. And i want to cache that data so that if to open that activity it should get it from the cache not from the http every time.
also i am thinking add some flag to clear out the cache (if for some reason if my url changes it should not read fro cache version rather get the latest urls
I am not sure what to use cache inside the sd card vs sqllite.
my listview contains the url, artist, name, …. these are all reference something like this:
<song>
<id>1</id>
<title>Someone Like You</title>
<artist>Adele</artist>
<duration>4:47</duration>
<plays>1662</plays>
<songs_url>http://website/music/someonelikeyou.mp3</songs_url>
<thumb_url>http://website/music/images/adele.png</thumb_url>
</song>
here is the code that reads from http:
// Getting XML from URL making HTTP request
// @param url string
public String getXmlFromUrl(String url) {
String xml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}
SQLite of course. It was done for holding such king of information. It is fast and easie to select filtered information.
For images (like thumbs) use cache folder:
context.getExternalCacheDir().getAbsolutePath()