Hi, can anyone explain when/why to close the SQlite database?

cutemover

New member
Jul 26, 2015
3
0
0
Visit site
I am new to android and i just started developing an application. Is it really necessary to close the database after accessing it? Any response would be greatly appreciated.
 

Rukbat

Retired Moderator
Feb 12, 2012
44,529
28
0
Visit site
If you're only selecting, and you don't keep opening it over and over, no. (If you keep opening it without closing it, you could be creating the equivalent of a memory leak.)

If you're updating, inserting or deleting it, you not only have to close it, it should be inside a transaction, so you know if the query failed or not, and you can roll it back if it did.
 

Members online

Forum statistics

Threads
945,126
Messages
6,924,295
Members
3,159,674
Latest member
Cloud Himalaya