views:

84

answers:

2

I need to store data to use in my android program. Here are the details about the data:

  • There will be one table. Each "row" of data will have a unique INT identifier. Other then that field, there will be four other INT fields and a text field. The string field will probably be a 2 or 3 sentences long. Each of the 4 INT fields will correspond to the ID of other rows.

  • There will be 100 rows, maybe 200. But all the rows will be read-only, and pre-populated.

  • The data will be read frequently, and non-sequentially.

The first answer for storing data is SQLite a lot of times, but given the particulars of the data, another storage method might be more efficient. I'm open to any suggestions, and code examples are always welcome!

+2  A: 

How about a static xml or cvs file in your assets? If it's too slow to access the file each time you need it (since you say it'll be read frequently), you could simply parse it into a map (HashMap or whatever it is in Java) when your program starts. You could also read it into SQLite the first time your program is run, and then use that database from there on, but you probably don't need to do that.

Benny Jobigan
I would probably start with this, and then switch to SQLite or something like that later if I found it to be necessary.
MatrixFrog
Hmm.. so when I read the XML, I would read it into a HashMap. The Unique ID would be the key of the map, and the value would be an array of the values. Am I understanding this right?
Bromide
Yea, that's what you'd do if you decide to go with my suggestion.
Benny Jobigan
A: 

Method 1, use SQLite, it works well and is in Android already. There is an sqlite example on the net (sorry I have lost the url) - google it :)

Method 2, write a streamed file to your SD Card with your data! there is an example in ApiDemos that does that and just add a file reader to collect your data from a sequential flat file. Nom.

Method 3, Write it as a post to the cloud. Am looking for code to do that myself, please post some here to save me time......

Droid
These 3 methods are really too complicated for a small static 'database' of information like the OP is using.
Benny Jobigan
No, the SQLite method is the best you can get
ognian