I have a database helper class
private static class DatabaseHelper extends SQLiteOpenHelper{
DatabaseHelper(Context context){
super(context,DATABASE_NAME,null,DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){
Log.w(TAG, "Upgrading database from version " + oldVersion + "to" + newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS titles");
onCreate(db);
}
}
on my project, I need to create a new object of this DatabaseHelper like DatabaseHelper aa = new DatabaseHelper(context). If that will execute db.execSQL(DATABASE_CREATE); every time when my program start? This line is for creating a new database;
No it will not be called every time. About the open helper and the code you postet you need to know 2 things:
OnCreate will only called once (when your database is first created). Then (as long as your database exists) this code will never be called again.
since you call manually onCreate() in your onUpgrade (which I wouldnt recommend):
In your super constructor you parse a Database version. This version is stored by the helper and as long this version stays same the onUpgrade will not be called.
2.