相关疑难解决方法(0)

在Android中管理SQLite连接

关于在Android中处理SQLite数据库连接,我有一个(希望)快速的问题.我有一个自然地由几个活动组成的应用程序.我创建/更新/查询数据库没有问题,因为我已经创建了一个专用的类来通过SQLiteOpenHelper等来处理这项工作.

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

或者换句话说,有没有理由不存储单例实例?

我也想知道幕后是否有类似于.NET连接池的事情,以降低打开连接的成本.

提前致谢!

architecture sqlite android

18
推荐指数
2
解决办法
8779
查看次数

使用Spock和Robospock创建SQLite数据库的单元测试

spock-core:0.7-groovy-2.0
robospock:0.5.0
Android Studio 0.8.2
Fedora release 20 (Heisenbug)
Run Code Online (Sandbox Code Playgroud)

这是完整的解决方案.现在它成功编译并运行单元测试,目录结构与预览编辑相同.请随意评论任何看起来不正确的事情.

编辑解决方案=====

的build.gradle:

apply plugin: 'java'
apply plugin: 'groovy'

repositories {
    mavenCentral()

    maven {
        // Location of Android SDK for compiling otherwise get this error:
        /* Could not find com.android.support:support-v4:19.0.1.
           Required by:
           :testSQLite:unspecified > org.robospock:robospock:0.5.0 > org.robolectric:robolectric:2.3 */
        url "/home/steve/local/android-studio/sdk/extras/android/m2repository/"
    }
}

dependencies {
    // just compile so we can use the sqlite API
    compile 'com.google.android:android:4.1.1.4', {
        // Do not bring in dependencies
        transitive = false
    }

    testCompile 'org.codehaus.groovy:groovy:2.3.+'
    testCompile 'org.spockframework:spock-core:0.7-groovy-2.0' …
Run Code Online (Sandbox Code Playgroud)

java sqlite android unit-testing robospock

18
推荐指数
2
解决办法
2701
查看次数

标签 统计

android ×2

sqlite ×2

architecture ×1

java ×1

robospock ×1

unit-testing ×1