简体   繁体   English

我们何时应在Android应用程序中使用db.close()?

[英]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; 如果活动使用私有SQLiteOpenHelper,则在其上调用.open()并使用数据库; when should we call .close()? 我们什么时候应该调用.close()?

Furthermore, what are the repercussions of not using .close() properly 此外,没有正确使用.close()有什么影响?

open() sets a lock on the database, so that no other instance can use it. open()在数据库上设置一个锁,以便其他任何实例都不能使用它。 so close() is a necessity that you are done with using the database , This is to ensure there are no discrepancies in the data. 因此close()是使用数据库的必要条件,这是为了确保数据中没有差异。 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. 因此,只能为您的数据库创建一个实例,这需要适当的锁定和解锁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM