2

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 ?

gandharv09
  • 257
  • 5
  • 17

1 Answers1

2

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

Community
  • 1
  • 1
Nathaniel D. Waggoner
  • 2,856
  • 2
  • 19
  • 41
  • can u share a better implementation of the database code ? which shows reading and writing to database from my List of objects . My java object "Data" is like: public class Data { private String discount; private String location; private String name; private String Image; private String Description; } I get a list of these objects after parsing. – gandharv09 Dec 19 '13 at 18:37
  • I would recommend you read the linked android documentation, as that covers the topic very thoroughly and has plenty of sample code to get your going. – Nathaniel D. Waggoner Dec 19 '13 at 18:38
  • Added a link to a good db tutorial that gives you a more complete code picture than the docs. – Nathaniel D. Waggoner Dec 19 '13 at 18:44
  • Also will it be fine to use shared preferences ? i have a list of about 100 resturants with their location name description and image link . – gandharv09 Dec 19 '13 at 18:44
  • I wouldn't recommend Shared Preferences, it's not really suited to this task in my opinion. You could use it for this, but your data is complex enough that Key/Value pairs aren't really the best modeling technique imo. – Nathaniel D. Waggoner Dec 19 '13 at 18:47
  • I need some further suggestion on the 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 ? – gandharv09 Dec 21 '13 at 14:05
  • http://stackoverflow.com/questions/9357668/how-to-store-image-in-sqlite-database For storign direct to database, but this isn't a good idea. http://stackoverflow.com/questions/9273008/android-save-images-to-sqlite-or-sdcard-or-memory/9273045#9273045 For the better choice – Nathaniel D. Waggoner Dec 23 '13 at 04:48