vendredi 24 juillet 2015

does Android database get created each time i run my app

I am new to android app development and i am creating an app which creates a database. I have a few question regarding this.

  1. Each time i launch my app does my app create a new database or will it use the previous database.

  2. If it does then how to stop it and use previous database.

  3. I am using physical device to run my app instead of using an emulator... how do i view where is my database

following is my code

public class ExternalDbOpenHelper extends SQLiteOpenHelper{
public static final String DB_Name = "mydatabase";
public static final String Table_Name = "Records";


public ExternalDbOpenHelper(Context context) {
    super(context, DB_Name, null, 1);
   SQLiteDatabase db = this.getWritableDatabase();
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table " + Table_Name + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, col1 text) ");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("Drop table if exists " + Table_Name);
}
}

Aucun commentaire:

Enregistrer un commentaire