Question

I am parsing a Rss feed using sax parser in android. I am able to display the data online when net is connected but i also want it to work for offline use and update it when it gets connected again to internet / wifi. I have no clue how to go about it.

What should be my best approach now ? should i construct Sql database ? considering i have images as well. Or there is any other simpler way. I would prefer simpler way.

I need some further suggestion on the Sql database approach here, First : My rss feeds gives image url links which i diplay using bitmap and insutstream at runtime but now for offline purpose i need to save complete images like whatsapp does right ? is this right ? if yes how to save complete images in database ? And last i want to save the complete database on sd card not in internal memory , storing data on sd card will work fine or it will create problem ? because whatsapp stores quite a data in internal memory !! if storing on sd card is not a problem how do i store complete data on sd card ?

Was it helpful?

Solution

This depends on how long you want the data to persist. Ask yourself:

Should this data be available to the users after rebooting the phone, or after force closing the app? Should it be available regardless of the last time I had connectivity, as up to date as possible given that?

In that case, then yes - you should use a database. Android has a number of built in helper classes for sqlite databases.

http://developer.android.com/training/basics/data-storage/databases.html

Which should get you started.

The images are pretty straight forward as you'll just stash a reference to the image(s) in the db. You would of course write these images to disk as well (on the sd card or some other place...) See:

Save bitmap to location

Your other options, afaik are:

1) SharedPreferences (not really suited to this).

2) Serializing your data and writing out/reading in from some file.

If you're still looking for more information on Database concepts and Android, here is a very good tutorial on the topic:

http://www.vogella.com/articles/AndroidSQLite/article.html

OTHER TIPS

You can use droidQuery to download the RSS Feed and cache it. Working off of this gist, which expects you to use the android-rss library, you can add the following cache flags to your AjaxOptions object:

.cache(true).cacheTimeout(AjaxCache.TIMEOUT_NEVER)

This will make it so the response is cached until you explicitly call:

AjaxCache.sharedCache().clearCache();

Which you can do after the network is connected (for help on this, check out NetWatcher).

Note that using this cacheing mechanism allows a very simple solution that will only store as long as the app process is live. If you want to save across sessions - so that if the user opens the app later and is not online, you will want to use something more complex and long-lasting, such as SharedPreferences or SQLite. A good list of options can be found here.

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