Question

Actually, i am fetching XML from the web, parsing it and display it on the screen. The problem which i am getting is that the activity tries to load the data from web each time the activity is called.(Actually, my mobile app requires frequent trips to the server) So i am in search of the below solution:

On Re-launch of an activity, the data from web should not be loaded again. 
creating a class that i can use to transparently make application faster by
selectively caching items in memory.  And thus, making users very happy and 
This class can even apply individual refresh times to each cached item.

So, i think i need to store the data in Cache or something like that.

Is there any way/technique to implement such thing ? so that it need not to load every-time on Re-launch of an activity.

Was it helpful?

Solution

Not sure what the performance would be with this suggestion, but the by far easiest if you just want to avoid fetching the XML files every time your activity re-launches, is to save them to Internal Storage. When your activity (re-)launches, you'll start by checking if the files exist locally before you fetch them from the web.

You would of course need come kind of logic to tell whether an XML file is "out of date" (you could have a simple database table with file names and last-fetched dates), and you would probably also like to have some kind of clean-up logic to delete files when you no longer need them so they don't fill up unnecessary space.

OTHER TIPS

You could try using a Service for loading the data in the background at given intervals.

Well what I would have done is to make a table , lets say call it "Table_Web_XML" , and appropriate fields in it to store specific web data .

When starting the Activity I would have first check if there is data in the database. If the table is empty (meaning the Activity is loading for the first time ) , I would load it from the web and display on the screen and save in database.

On the other hand if there is data in the table, then i would load it on the screen, and would start a service in background that would update my database table if there is any changes in it on the Web . What this would do is for system response point of view, the data will always be loaded fast, when the activity is repeatedly opened, and background service will ensure new and latest content on subsequent requests :) . Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top