1

I am new to Android development and I am trying to make a Trivia application.

I need to store the data relating to questions somewhere and I am not entirely sure where to store it.

I plan to have multiple people playing so I need each person to have the same questions.

Basically I planned to have a list of categories and within each category I had question objects.

The question objects contained information regarding the question such as the answers and question itself.

However, if I use a database, I believe none of this would be needed due the questions being stored in tables which would represent categories.

In terms of speed what would be better:

  • to store it in a database
  • or to read from a file every time the application is loaded and store the data within a data structure?
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Wuffle
  • 73
  • 1
  • 14

2 Answers2

2

You almost certainly want a database. Databases are made for fast search and easy insertion/deletion. There's really no advantage to having a file and doing in memory parsing each time.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
1

Aside from performance benefits, here's a simple list of advantages of using SQLite rather than flat file:

  • You can query items as you wish -- don't need to load all of them and select which ones you need.

  • Record deletion is a much less painful process. No rewriting of whole files into wherever.

  • Updating a record is as easy as removing or creating one.

  • Have you ever tried doing cross-referencing lookups on a flat file? Just.Not.Worth.It.

To summarize, it's every advantage a Database has over a text file.

Answer by josephus

Community
  • 1
  • 1
diogojme
  • 2,309
  • 1
  • 19
  • 25