Shane
Shane

Reputation: 2375

When should we use db.close() in our android applications?

If an activity uses a private SQLiteOpenHelper, calls .open() on it and uses the database; when should we call .close()?

Furthermore, what are the repercussions of not using .close() properly

Upvotes: 0

Views: 90

Answers (1)

Yashwanth Kumar
Yashwanth Kumar

Reputation: 29121

open() sets a lock on the database, so that no other instance can use it. so close() is a necessity that you are done with using the database , This is to ensure there are no discrepancies in the data. think about another instance changing the data, that you are trying to access. so only 1 instance can be made for your db, which requires,proper locking and unlocking.

Upvotes: 1

Related Questions