Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 777
Yoo Matsuo Avatar asked Jun 14 '10 06:06

Yoo Matsuo


1 Answers

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.

like image 194
CommonsWare Avatar answered Sep 26 '22 16:09

CommonsWare