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!
When storing sensitive data—data that shouldn't be accessible from any other app—use internal storage, preferences, or a database. Internal storage has the added benefit of the data being hidden from users. Android provides two types of physical storage locations: internal storage and external storage.
To read and write in the android internal storage we have two methods OpenFileOutput (): used for creating and saving a file. This method returns a FileOutputStream instance. Context.MODE_PRIVATE: If the file exists then it is overiddent else a new file is created.
Categories of storage locations Android provides two types of physical storage locations: internal storage and external storage. On most devices, internal storage is smaller than external storage. However, internal storage is always available on all devices, making it a more reliable place to put data on which your app depends.
If you have data that's only meaningful for your app, use app-specific storage. For shareable media content, use shared storage so that other apps can access the content. For structured data, use either preferences (for key-value data) or a database (for data that contains more than 2 columns). Should the data be private to your app?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With