I have some 34 checkboxes on one Activity which i have to mark and unmark. and I want to save the status of the each checkbox.
I want this persistently. So should i have a sqlite table or preferences ?
If sqlite table is recommended, then what should be the ideal table structure design?
You could do it either by using SQLite or preferences. Though… what you want to do is kind of simple, so why would you care of creating a table, creating
SQliteOpenHelperobjects, designing a table, etc. The preferences approach is simpler.So… what is most important here is how you identify your checkboxes. If you have just 34 static checkboxes (meaning they won’t change its order) and they are into an array (which would be ideal), you have it easy.
As you might know, preferences editor does not allow to save arrays. So you have some choices:
putBoolean("checkbox2", true);putBoolean("checkbox3", false); ect.)putString("checkboxes_state", "10101011100011010"); this way you will have a String with 34 chars, each char represents a state.longequals or lower than 17179869183. For instanceputLong("checkboxes_state", 17179869183)would mean that all checkboxes are selected (because its binary representation is 1111111111111111111111111111111111). More examples:Edit
With regards to your question of why the last one is more efficient let me briefly explain. The first one implies using 34 preferences slots (actually I don’t know how they are stored; hopefully, android team took care of performance). The second approach will use a 34 chars String; so, the minimum size that the String object would have is:
Meaning that a String of that lengthen will take up at least 113 bytes. On the other hand, using just one long will take up 8 bytes only. The less bytes to work with, the faster your app will be (because Android will have to process and save less bytes).