java - How to add initial data for DB using GreenDao in android? -
i have been answer insert initial data in native mode
how add initial data sqlite database?
how can same result using green dao?
this application class
public class app extends application{ @override public void oncreate() { super.oncreate(); daomaster.devopenhelper helper = new daomaster.devopenhelper(this,"images-bd",null); sqlitedatabase db = helper.getwritabledatabase(); daomaster daomaster = new daomaster(db); daosession daosession = daomaster.newsession(); } }
you can create class extends daomaster
, run queries inside oncreate
method:
public class customdaomaster extends daomaster { public customdaomaster(sqlitedatabase db) { super(db); } public static class openhelper extends daomaster.openhelper { public openhelper(context context, string name, sqlitedatabase.cursorfactory factory) { super(context, name, factory); } @override public void oncreate(sqlitedatabase db) { super.oncreate(db); db.execsql("insert mytable values('foo')"); db.execsql("insert mytable values('bar')"); } } }
so, in application
class, use instance of class:
public class app extends application { @override public void oncreate() { super.oncreate(); customdaomaster.openhelper helper = new customdaomaster.openhelper(this, "images-bd", null); sqlitedatabase db = helper.getwritabledatabase(); customdaomaster daomaster = new customdaomaster(db); daosession daosession = daomaster.newsession(); } }
Comments
Post a Comment