I am making a card game for Android where a player can choose from a selection of cards to build a deck that would contain around 60 cards. Currently, I have the entire database of cards created that the user can browse.

The next step is allowing the user to select cards and create a deck with whatever cards they would like. I have a form where the user can search for specific cards based off a few different attributes. The search results are displayed in a List Activity. My thought about deck creation is to add the primary key of each card the user selects to a SQLite Database table with the amount they would like in the deck.

This way as the user performs searches for cards they can see the state of the deck. Once the user decides to save the deck. I'll export the card list to XML and wipe the contents of the table. If the user wanted to make changes to the deck, they would load it, it would be parsed back into the table so they could make the changes. A similar situation would occur when the eventually load the deck to play a game.

I'm just curious what the rest of you may think of this method. Currently, this is a personal project and I am the only one working on it. If I can figure out the best implementation before I even begin coding I'm hoping to save myself some time and trouble.

  • Well to clear some things up, I want the user to be able to be able to see the deck that they are creating. I had thought that passing around an array or something similar might become messy because they are going to be using the form, and then interacting with a List Activity that displays the results. Essentially, what I'm not sure how to go about is to keep the deck in progress displayed, while allowing them to continue to add cards. I probably could just keep the Deck of cards in the database, but I wasn't sure if that would be the best way to go about it. Commented Nov 19, 2012 at 13:41

2 Answers 2


The database seems a bit pointless to me, if you don't need the data to be persistent you shouldn't be using a database, just an an array of structs instead.

The cards however should be stored as a database to allow the system to be easily expanded, just remember to keep SQL injection in mind.

  • 1
    There seems to be some advantage of querying the data from SQL here.
    – Jan Hudec
    Commented Nov 19, 2012 at 9:57
  • In his description he is not querying the data being stored in the database (the deck) he is querying the selection of cards (he doesn't mention how these are stored) Commented Nov 19, 2012 at 12:06
  • I understood the question so that he needs to query both together and that's why it's in a database. But it's true it's not very clear as written.
    – Jan Hudec
    Commented Nov 19, 2012 at 12:37

Unless the XML is given to you, I would probably just keep the deck stored in the database. But I suspect it's there for interoperability with some other application, so it has to be there.

If loading the data in the database makes it easier for you to manipulate them, go ahead. But to limit amount of writes to the non-volatile storage, you should take advantage of the memory tables support in SQLite. In-memory tables can be created in two ways:

  • CREATE TEMP TABLE ... with PRAGMA temp_store = MEMORY in effect.
  • ATTACH ':memory:' AS mem and CREATE TABLE mem.....

Advantage of memory table compared to on-disk table that you drop before exiting is that it will not stay around if your application is forcibly closed. So you don't have to drop it in onStop and it still won't stay around when your application is killed, which Android does without further warning (of course you still need to write the XML in onStop).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.