Search code examples
androiddatabasesqliterss-reader

Android Storing RSS feed parsed data in a database for offline use


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 ?


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