从我以这种方式实例化的片段
fmdata = new FileManagerData(getActivity());
下面的课。我不明白为什么没有调用 onCreate() 并且没有创建我的数据库。
public class FileManagerData {
public static final String TAG = FileManagerData.class.getSimpleName();;
Context context;
DBHelper dbHelper;
public FileManagerData (Context context){
this.context = context;
dbHelper = new DBHelper();
}
private class DBHelper extends SQLiteOpenHelper{
private static final String DB_NAME = "filename.db";
private static final String DB_SQL = "filename.sql";
private static final int DB_VERSION = 1; // internal number
public DBHelper() {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// this is NEVER called and my DB does not exist yet
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
编辑:诀窍是必须使用数据库(读取或写入)所以 onCreate() 被调用。