Sunday, 15 August 2010

android - Performance/memory consumption for saving infos in DB or prefs -



android - Performance/memory consumption for saving infos in DB or prefs -

i need store lot , variable number of checkboxes status of android application. every 5-10 mins need retrieve status of single checkbox (that should changed user interaction in other activity). know can store them on sharedpreferences or in sqlite db. number or checkboxes variable 10 (infinite-1).

my first thought store statuses in 1 single string:

chk1:true,chk2:false,chk3:false,chk4:false,chk5:true

delimited : , ,. can retrieve in 1 single getstring() call, checkboxes stasus.

i left solution because checkboxes growing in number , think it's not performing have single string one thousand of data.

my sec thought store every chk in separate preferences. left solution because cause need retrieve may times checkboxes status.. imagine getstring() called 10000 or more times it's waste of resource.

my 3rd thought store single status in sqlite db.

id status 1 t 2 f 3 f 4 f 5 t

in solution don't need access db lots of time.

what's best solution (performance , memory consumption) if need retrieve checkbox status every 5 mins infinite? db or sharedpref? if db, need open every time db , instantiate cursor, or should instantiate @ origin of activity?

i'd go sqlite.

both shared preferences , sqlite have cache mechanisms, sqlite designed retrieval , storage of big amounts of info whereas shared preferences more suited simple application... well... preferences.

moreover sqlite particularly useful if info model ever changes (and believe me, happens time). sqlite cache used fragments of info (technically: pages of database) - adapt actual usage pattern of data.

as opening db - i'd recommend opening 1 time , reuse created connection multiple times - save overhead of opening database each time (which costly operation) , allow sqlite larn (adapt) how cache info based on how utilize (e.g. order of access, particular sql statement cache, etc.)

android performance sqlite sharedpreferences

No comments:

Post a Comment