android - calling onCreate method from inside another method -
i have never seen explicitly call 1 of system callback methods oncreate() or ondestroy() inside method. looks wrong. thought saw in example , can not believe it. imagination or real?
in code below onupgrade() method of sqliteopenhelper class, calling oncreate() method explicitly function. possible call oncreate() inside method? , there better way without calling oncreate()?
private static class databasehelper extends sqliteopenhelper{ databasehelper(context context){ super(context, database_name, null, database_version); } @override public void oncreate(sqlitedatabase db) { db.execsql("create table if not exists " + table_name + " (" + lentitems.note_id + "id integer primary key autoincrement, " + lentitems.title + " text, " + lentitems.text + " text);"); } @override public void onupgrade(sqlitedatabase db, int previousversion, int newversion) { db.execsql("drop table if exists " + table_name); oncreate(db); // <-- explicit call oncreate } } // end databasehelper inner class
the call there correct, oncreate() called once when database first created. onupgrade called when database version changed. when drop table in onupgrade have call oncreate there create new table oncreate changed reflect new table.
Comments
Post a Comment