What is the best method to store this small read-only data table in an android phone?
Asked Answered
A

2

7

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!

Abysmal answered 24/7, 2010 at 2:6 Comment(2)
I feel like this is a sort of lateral thinking puzzle, where the question is "What kind of app is Bromide writing?" A sort of "choose your own adventure" game is the first thing that comes to mind.Virtuosity
lol Well, help me store some data, and maybe we'll all find out ;-)Abysmal
M
2

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.

Meagher answered 24/7, 2010 at 2:32 Comment(3)
I would probably start with this, and then switch to SQLite or something like that later if I found it to be necessary.Virtuosity
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?Abysmal
Yea, that's what you'd do if you decide to go with my suggestion.Meagher
O
0

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......

Overmatter answered 24/7, 2010 at 7:39 Comment(2)
These 3 methods are really too complicated for a small static 'database' of information like the OP is using.Meagher
No, the SQLite method is the best you can getKaliope

© 2022 - 2024 — McMap. All rights reserved.