I have a class DatabaseHandler. I have overridden the onCreate(SQLiteDatabase db) method with the following code :
String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_SONG + "(" + ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
SONG_TITLE + " TEXT," + ARTIST_NAME + " TEXT," + GENRE + " TEXT," +
SONG_PATH + " TEXT" + ")";
db.execSQL(CREATE_TABLE);
but I found that there were extra items getting appended to the TABLE_SONG everytime I opened the emulator as a result of which even though I had 6 songs in the sdcard the database showed 454 songs. This forced me to drop the table with a thought of recreating it again. But now I am stuck that the table could not be found or rather is not getting created. Shouldnt it be that the onCreate() method should get called everytime when I create an object of this class?
I agree with waqas please find sample code below
EDIT
USE of onUpgrade()
It is called when you construct a SQLiteOpenHelper with version newer than the version of the opened database. What to do depends on the changes in the database that are made between the old and new versions. The only case when you don’t drop a changed table is when the change is noting more than an added column. Then you can use ALTER TABLE statement to add the new column to the table signature.