如果您查看父 OrmLiteSqliteOpenHelper class constructor 的文档:
public OrmLiteSqliteOpenHelper(android.content.Context context,
String databaseName,
android.database.sqlite.SQLiteDatabase.CursorFactory factory,
int databaseVersion,
int configFileId)
Same as the other constructor with the addition of a file-id of the table config-file.
See OrmLiteConfigUtil for details.
Parameters:
configFileId - file-id which probably should be a R.raw.ormlite_config.txt or some
static value.
它会引导您查看OrmLiteConfigUtil for details。总而言之,在 Ice Cream Sandwich (Google API 15) 之前,Android 中对注释方法的调用非常非常昂贵,这导致人们在配置 10-15 个 DAO 时看到 2-3 秒的启动时间。所以他们添加了一个实用程序类来转换你的注释并编写一个配置文件。然后可以将该文件加载到 DaoManager 中,而无需对注解进行任何运行时调用。
因此,根据您的 minSDKVersion,如果它是 Ice Cream Sandwich (Google API 15) 或更高版本,那么您可以继续使用注释。 Looking at the source,您只需为 configFile 传递 null:
public class MyDatabaseHelper extends OrmLiteSqliteOpenHelper {
public static final String DATABASE_NAME = "Example.db";
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_PASSWORD = "Password";
public MyDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION, (InputStream)null, DATABASE_PASSWORD);
}
}
注意:为避免构造函数出现模棱两可的问题,请务必强制转换为 null。
如果您的 minSDKVersion 低于 Google API 15(例如 Honeycomb),那么您应该为您的类创建一个配置文件。
OrmLiteConfigUtil.writeConfigFile("ormlite_config.txt");
然后你会将 R.raw.ormlite_config.txt 传递给上面的构造函数,而不是 null。