Jedi Schmedi
Jedi Schmedi

Reputation: 818

How to handle data in android

Im working on a self-test app. And I wondering on how to store the data, I've got over 200 questions and more is on the way. Was thinking of storing them as XML but didnt find a way to get a random question without reading the whole string-array to a variable, which is bad for the memory. So the correct way to go is to use a SQL-database, right?

But how do I make such a database so that it exists at boot and dont need to be made during start up? Can't seem to find any tutorial on this subject, on how to handle questionnaires.

Upvotes: 2

Views: 213

Answers (2)

Franci Penov
Franci Penov

Reputation: 75982

Here's a good tutorial on SQLite and Content Provider. It'll introduce you to using SQL databases on Android, and wrapping them into a ContentProvider.

As for how to get the data to the device - you have two options:

  • You pack the SQLite .db file in the application assets folder. Pros: the database is ready for consumption on the first run of the app. Cons: your .apk is too big. Updating is hard.
  • You download the data on the first run. Pros: your .apk is slim. updating is easy Cons: there's a delay before the user can use the app.
  • You ship a small .db file with the first 10 questions. Pros: Your users can start using the app immediately, while you download the rest of the questions in the background. Cons: You have to pick 10 questions you're likely to never or rarely change, or you risk your app to start with outdated data.

Upvotes: 2

Gabe Sechan
Gabe Sechan

Reputation: 93561

Create the db offline and either put it in the apk or download it.

Upvotes: 0

Related Questions