A SQLiteConnection object for database '/data/data/.../databases/....db' was leaked!

时间:2014-07-28 15:02:33   收藏:0   阅读:1781

详细异常:

A SQLiteConnection object for database ‘/data/data/.../databases/....db‘ was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed

 

明显是数据库操作异常,数据库对象被锁,明确告诉你对象长久不用需要关闭。

 

改正:获取数据库对象改成单例模式,项目运行中只保证唯一一个对象即可。如下:

private static XXXXSQLHelper mInstance = null;

public synchronized static XXXXSQLHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new XXXXSQLHelper(context);
}
return mInstance;
};

 

调用如下:

public XXXXDBUtil(Context context) {
mSQLiteDatabase = XXXXSQLHelper.getInstance(context)
.getWritableDatabase();
}

 

注意:此时数据库对象是唯一实例了,不需要close了,如果close掉,将会出现对象已关闭的严重异常,导致程序崩溃。

 

A SQLiteConnection object for database '/data/data/.../databases/....db' was leaked!,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!