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

cutemover

New member
Jul 26, 2015
3
0
0
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.
 
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.
 

Forum statistics

Threads
955,889
Messages
6,966,016
Members
3,163,419
Latest member
AndLesUK