Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance/memory consumption for saving infos in DB or prefs
    text
    copied!<p>I need to store a lot and variable number of checkboxes status of my Android application. Every 5-10 mins I need to retrieve the status of a single checkbox (that should be changed by user interaction in other activity). I know i can store them on sharedPreferences or in a SQLite db. The number or checkboxes is variable from 10 to <em>(infinite-1)</em>. </p> <p>My first idea was to store all statuses in one single string:</p> <pre><code>chk1:true,chk2:false,chk3:false,chk4:false,chk5:true </code></pre> <p>delimited by <code>:</code> and <code>,</code>. I can retrieve in one single <code>getString()</code> call, all my checkboxes stasus.</p> <p>I left this solution because my checkboxes are growing in number and I think it's not performing to have a single string with thousand of data.</p> <p>My second idea was to store every chk in separate preferences. I left this solution because cause I need to retrieve may times my checkboxes status.. imagine <code>getString()</code> called 10000 or more times it's a waste of resource.</p> <p>My third idea is to store all single status in a SQLite db.</p> <pre><code> ID Status 1 T 2 F 3 F 4 F 5 T </code></pre> <p>In this solution I don't like that I need to access my DB lots of time.</p> <p>What's the best solution (performance and memory consumption) if I need to retrieve a checkbox status every 5 mins from now to infinite? <strong>DB or sharedpref</strong>? If DB, I need to open every time the db and instantiate a Cursor, or should I instantiate it at the beginning of my activity?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload