我们如何才能重新获得Greendao DB关闭错误?

时间:2017-05-30 13:21:27

标签: android android-sqlite greendao greendao-generator greendao3

什么时候我们可以创建greendao应用程序我们没有得到任何默认方法来关闭greendao db所以我们如何关闭应用程序类的数据库

因为我们在Application class

上添加了以下代码

静态类YourAsyncTask扩展了AsyncTask {

    @Override
    protected String doInBackground(Void... unused) {
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(mContext, ENCRYPTED ? "otp-db-encrypted" : "otp-db");
        Database db = ENCRYPTED ? helper.getEncryptedWritableDb("super-secret") : helper.getWritableDb();
        daoSession = new DaoMaster(db).newSession();
        return "";
    }
}

我们可以将daoSession对象用于整个应用程序,以便我们可以获得以下错误的解决方案

完成尚未停用或关闭的光标。 database = /data/user/0/com.onetouchprotect/databases/google_app_measurement_local.db,table = null,query = select count(1)from messages                                                                      android.database.sqlite.DatabaseObjectNotClosedException:应用程序未关闭此处打开的游标或数据库对象                                                                          在android.database.sqlite.SQLiteCursor。(SQLiteCursor.java:98)                                                                          在android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:50)                                                                          在android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1618)                                                                          在android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1557)                                                                          在com.google.android.gms.internal.zzatg.zza(未知来源)                                                                          在com.google.android.gms.internal.zzatg.zza(未知来源)                                                                          在com.google.android.gms.internal.zzatw.zzc(未知来源)                                                                          在com.google.android.gms.internal.zzatu.zzb(未知来源)                                                                          在com.google.android.gms.internal.zzatu.zza(未知来源)                                                                          在com.google.android.gms.internal.zzatu $ 4.run(未知来源)                                                                          at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:428)                                                                          在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                          在com.google.android.gms.internal.zzato $ zzd.run(未知来源)

1 个答案:

答案 0 :(得分:0)

建议有一个单独的类来负责为您提供会话变量。引导您使用DaoExample

文件中的App.java