androidnerd
androidnerd

Reputation: 209

Should I use array or database

I am writing an app that contains a list of items with their information. When the users open the app, they would see the list, and when they select a particular item, they would get all the information about that item.

Right now my approach is I store the data in a multidimensional array in the java source file. When I push a new update, I might add new items in the java source file (so the array gets bigger). I wonder if this is the best approach. I tried looking up relevant information about array and database on the Internet, but I can't seem to find the information I need. Any advice for me?

Also, if in the future, I create a function for users to add their own items to the list, what's the impact?

Upvotes: 1

Views: 489

Answers (5)

Reynard
Reynard

Reputation: 331

The database is good for permanent data, but realize it can create a bottleneck if writing to disk is not really necessary.

I am in the middle of refactoring an App to no longer use SQLite. I was inserting large amounts(10,000-100,000) of new rows at once, and it looked like it was going to take an hour based on my log feedback of the status. When I keep it in memory, it all loaded in about 5 seconds.

Upvotes: 0

AndroidPenguin
AndroidPenguin

Reputation: 3453

An analysis of the storage options and what they're commonly used for can be found here. Personally I suggest SQLite database.

Upvotes: 0

Jeremy D
Jeremy D

Reputation: 4855

You can use a SQLite database stored directly on your phone (sd card for example).

Upvotes: 0

Vincent Mimoun-Prat
Vincent Mimoun-Prat

Reputation: 28541

If the user should be able to update it, if you should be able to update it dynamically (for instance update from internet), then the database is a must.

If that data is static and won't change unless you update the app, you can store it in the code or better, in a file (you can store in JSON format for ease of reading & parsing)

Upvotes: 1

user903772
user903772

Reputation: 1562

If use array, the newly added items by the user will be gone when the app restarts.

Upvotes: 0

Related Questions