切勿接近Android的SQLite的连接 [英] Never close Android SQLite connection

查看:139
本文介绍了切勿接近Android的SQLite的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你根本不会关闭您的连接会发生什么情况?我知道你会得到异常,如果你不关闭并尝试打开一个又一个,但如果你有一个全球性的单身会发生什么,你根本就没有关闭它?你知道吗?

What happens if you simply never close your connection? I know you get exceptions if you don't close it and try to open another one, but what happens if you have a global singleton, and you simply don't close it? Any idea?

推荐答案

形成于时空连续的裂痕,威胁着所有的生命在宇宙中灭绝,直到有一天被保存了一堆人在brightly-的各色古怪的服装(包括一些的披肩的,如果你能相信它)。

A rift is formed in the space-time continuum, threatening extinction of all life in the universe, until the day is saved by a bunch of humans in brightly-colored funny-looking outfits (including some with capes, if you can believe it).

哦,不,等等。这只是一本漫画书。

Oh, no, wait. That was just a comic book.

其实,没有什么会发生。有人告诉我,由谷歌和其他Android专家,由于方式SQLite的作品(尤其是它的交易处理),没有什么不好的,如果你不关闭数据库应该发生。

Actually, nothing much happens. I have been told, by Googlers and other Android experts, that due to the way SQLite works (particularly its handling of transactions), nothing bad should happen if you fail to close the database.

事实上,如果你实现一个内容提供商,你会有同样的效果,因为内容提供商不调用任何形式的的onDestroy()的方法,这意味着你永远不会有机会接近你的数据库。内容提供商将只活到这个过程被终止。就个人而言,这真的是我的错误,这是我要尽量减少我的使用内容提供商的原因之一。

In fact, if you implement a content provider, you will have this same effect, as content providers are not called with any sort of onDestroy() method, meaning you will never have an opportunity to close your database. A content provider will just live until the process is terminated. Personally, this really bugs me, which is one of the reasons I try to minimize my use of content providers.

这篇关于切勿接近Android的SQLite的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆