I'm novice in Android and I trying to create BD sqlite with API. My class exted SQLiteHelper, the constructor method is OK but the create method not is call. No error in compilation. My doubt not is when onCreate or onUpdate events are calls.
If I do 'wipe data' in VM, BD not is created. If I put new version (from 1 to 2, from 2 to 3,...), BD not is created. In Android Studio->Device Monitor->File Explorer, in app folder the BD and the folder not exist.
MainActivity.java code:
public class MainActivity extends ActionBarActivity {
private DBTesteHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dbHelper = new DBTesteHelper(this);
setContentView(R.layout.activity_main);
}
}
DBTesteHelper.java code:
public class DBTesteHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "bd_teste.db";
private static final int DATABASE_VERSION = 1;
public DBTesteHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE_STUDENT = "CREATE TABLE tb_estudante ("
+ " id INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ " name TEXT, "
+ " idade INTEGER, "
+ " email TEXT )";
db.execSQL(CREATE_TABLE_STUDENT);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS tb_estudante");
onCreate(db);
}
}