Yoo Matsuo
Yoo Matsuo

Reputation: 2363

When should I call a close method of a SQLite database in Android

I want to know when a close method of a sqlite database should be called in a life cycle, since the NotePad sample in the sdk (http://developer.android.com/resources/tutorials/notepad/index.html) doesn't call NotesDbAdapter.close(), it implements that method though.

My application accesses the db not so frequently, but some, it depends on user requests. I think I should open the db at the onCreate, and close it at the onDestroy. Is that a good practice?

Thanks in advance, yokyo

Upvotes: 5

Views: 1562

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006674

I think I should open the db at the onCreate, and close it at the onDestroy. Is that a good practice?

Yes, that is a fine pattern to use.

Upvotes: 5

Related Questions