详细异常:

A SQLiteConnection object for database '/data/data/.../database/....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/.../database/....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掉,将会出现对象已关闭的严重异常,导致程序崩溃。

相关文章:

  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
猜你喜欢
  • 2022-12-23
  • 2021-12-24
  • 2022-01-12
  • 2021-07-10
  • 2022-12-23
  • 2021-12-14
相关资源
相似解决方案