A SQLiteConnection object for database '/data/data/.../databases/....db' was leaked!
详细异常:
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掉,将会出现对象已关闭的严重异常,导致程序崩溃。
摘自:http://www.cnblogs.com/jiuzhexingfu/p/3872712.html