开发者

SQLiteDatabase Android Performance Question

From performance point of view, regardless of other constraints:

What is the cost of opening a SQLiteDatabase in the whole application lifecycl开发者_如何学JAVAe?


Is it worth the effort to open/close everytime needed (and maintaining state)?


If you use SQLiteOpenHelper, it will cache your database object meaning it will be opened only once and closed only once. You can then use getReadableDatabase() or getWriteableDatabase() wherever and whenever is convenient because you will be using the cached database.

SQLiteOpenHelper also makes it really easy to create, open, and upgrade (and with API 11, downgrade too) your database and is the Google recommended way of working with SQLite.


  1. Open the database once => One open/close
  2. Open the database multiple times => Multiple open/close

In 1) and 2), the memory cost is the same while the database is open. So 2) is obviously more expensive with this very reduced set of hypothesis.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜