3

From performance point of view, regardless of other constraints:

What is the cost of opening a SQLiteDatabase in the whole application lifecycle?


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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0
  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.

1 Comment

but there must be some cost for the database being open the whole process cycle?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.