开发者

android sqlite best practises for performance (direct data access via always open connection / cursor VS on demand access and custom objects)

im currently porting my iphone app to android. this app makes heavy use of sqlite data. on the iphone i populate my custom objects with sqlite data, open and close my connection to the database multiple times on demand

however on the android, i have not come across many tutorials which follow this approach. they simply use a cursor and show the data directly without making use of custom objects and collections

i wanted to know if the开发者_如何学运维re was any particular reason for this on the android? what would you suggest me to here? ie: is it feasible to have an always on connection / cursor the the sqlite db on the android and display the data directly OR go the iphone way that is to populate collection of custom objects from sqlite and have the UI data bound to this collection instead of the sqlite cursor

thanks in advance folks


I don't think optimal approach will vary with platform to any significant degree.

  1. Sqlite keeps caches in the connection, so it's usually advantageous to keep the connection open.
  2. You can save some time by preparing the statements once and reusing them.
  3. Query startup is quite significant, so join everything you will need in one query. Getting a list of objects in one query and than starting separate queries for individual objects is very slow compared to join statement.
  4. If you can populate the UI objects directly from the database, going through any intermediate objects is just putting unnecessary load on the memory manager (whether ga
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜