Oncreate is not called after creating the database!

We create a new database using the helper, but according to the document create must be called right after the database is created, but it is incorrectly called. can any plz help me solve this problem. Plz see the code below.

1) Is there a way to create a database instead of using an assistant, if so, plz advise me! 2) What calls will be made in creating the database, as well as when destroying the database?

OpenHelper(Context context) 
  {

     super(context, "examplee.db", null, 1 );
     SQLiteDatabase sqlite = null;       
      Log.w(TAG, "Openhelp database, ");
      sqlite =  context.openOrCreateDatabase("examplee.db", Context.MODE_PRIVATE, null );
      Log.e ( TAG,"SQ lite database object "+sqlite );                
  }

 public void onOpen(SQLiteDatabase db)
 {
     Log.e ( TAG,"On open called ");
 }


  @Override
  public void onCreate(SQLiteDatabase db) 
  {
      Log.w(TAG, " On create ");
      //db.execSQL(sql);
     //db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, name TEXT)");
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
  {
     Log.w(TAG, "Upgrading database, this will drop tables and recreate.");
     //db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
     //onCreate(db);
  }

}

Thanks in advance,

+3
source share
3 answers

Here is a very detailed description of how to delete a database file from your emulator (debugging on a real Android phone is very similar).

  • . , !

  • .

  • : 'adb shell' ( , ). Android Debug Bridge; . , unix.

  • . 'ls -l', , ( - unix).

  • , . , , , com.sillynames.myprogram5, "myblackbook.db". :

    /data/data/com.sillynames.myprogram5/databases/myblackbook.db

  • , "rm myblackbook.db".

, ! -

+5

SQLiteOpenHelper javadoc , onCreate ", ". ". , . , db .

, db adb /data/data/ < > /databases , employee.db.

onCreate . , .

+1

, , , plz !

, SQLite Manager sqlite db assets . , /data/data/your_app_package_name/databases/

: SQLite Android

, ?

When your database is created with a fist, a method is called onCreate(). And there is no possibility for kill/dropthe database, instead you can delete this db file.

0
source

Source: https://habr.com/ru/post/1794326/


All Articles