管理中的Andr​​oid SQLite的连接 [英] Managing SQLite Connections in Android

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

问题描述

我有关于Android中处理SQLite数据库连接的(希望)快速的问题。我有一个是由几个活动,自然的应用程序。我没有麻烦创建/更新/查询的数据库,我创建了一个单独的,专门类通过SQLiteOpenHelper来处理工作等。

I have a (hopefully) quick question regarding handling SQLite database connections in Android. I have an app that is composed, naturally, of several activities. I have no trouble creating/updating/querying the database, as I've created a single, dedicated class to handle that work via SQLiteOpenHelper, etc.

我的问题是这样的:由于这些活动都共享同一数据库中,这通常被实现为一个单一的,静态成员,还是应该每个活动拥有自己的连接?我当然关心的是重新连接到数据库中的每个活动的成本。

My question is this: since these activities all share this same database, is this usually implemented as a single, static member, or should each activity own its own connection? My concern of course is the cost of re-connecting to the database in each activity.

或者,换一种说法,没有任何理由不只是存储单一实例?

Or, put another way, is there any reason not to just store a singleton instance?

我也想知道,如果有什么东西会在后面类似.NET的连接池的场面,以减少打开连接的开销。

I'm also wondering if there's something going on behind the scenes similar to .NET's connection pooling to reduce the cost of opening connections.

在此先感谢!

推荐答案

连接开口SQLite是大约为0.2ms。

Connection opening in SQLite is about 0.2ms.

最好的实践告诉我们,打开每个需要一次性关闭连接。

The best practice tells us to open and close the connection each time we need one.

这篇关于管理中的Andr​​oid SQLite的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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