从片段我实例化这种方式
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()被调用。