我什么时候应该关闭DatabaseHelper?
参考此链接,什么时候是关闭连接的好时机,如果你只有一个连接?我有一项服务始终在后台运行。什么时候调用 close()
函数比较合适?有什么建议吗?
With reference to this link, when is a good time to close the connection if you only have one connection? I have a service running in the background at all times. When is a good time to call the close()
function? Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您实际上不必调用
close()
。例如,如果您实现内容提供程序,则没有机会调用close()
。我们被告知,由于 SQLite 的实现方式,不调用close()
不会导致任何特定问题。话虽如此,您确实应该重新考虑让“服务也始终在后台运行”。
You do not actually have to call
close()
. For example, if you implement a content provider, there is no opportunity to callclose()
. We have been told that, due to the way SQLite is implemented, not callingclose()
will not cause any particular problem.That being said, you really should reconsider having "a service running in the background too all the time".