0

在我的 android 应用程序中,该应用程序在应用程序开始时具有预处理步骤,该步骤从数据库加载应用程序所需的数据。SQLite 数据库的大小约为 40 MB。该应用程序需要花费大量时间来预处理来自数据库的数据,因此用户必须等待大约 1 分钟的时间才能使用该应用程序。有什么方法可以提高我的应用程序的性能吗?数据库操作大多是这样的选择类型:

Cursor mCursor = myDataBase.rawQuery("SELECT SUM(TimeTaken) as _time from AssessmentAttempted where AssesmentId IN(" + assessmentIds + ")", null);

4

1 回答 1

1

为了提高预处理阶段的性能,为对数据库进行的所有操作创建一个 SQL 事务。这将尤其减少插入和更新时间。

myDataBase.beginTransaction();
try {
    //make all the BD operations
    myDataBase.setTransactionSuccessful();
}catch {
    //Error in between database transaction 
}finally {
    myDataBase.endTransaction();
}
于 2012-11-09T12:31:14.897 回答