Using Green DAO with content provider Using Green DAO with content provider database database

Using Green DAO with content provider


I have a project running with greenDao and a content provider. First I was using ProviGen just to generate the content provider and query with the content resolver but then the project turned to be very large so I decided to implement greenDAO, what I did is to use the contentProvider created in provigen to get the database from it, so now I have both the contentProvider and provigen attached to the same database. I encourage you to create your ContentProvider and attach your daoMaster to the database generated with it. Here is the piece of code I used in the onCreate Application Class:

private static DaoSession daoSession;public void onCreate(){SQLiteOpenHelper myAppOpenHelper = new ProvigenContentProvider().openHelper(this); //ContentProvider created previouslySQLiteDatabase db = myAppOpenHelper.getWritableDatabase();DaoMaster daoMaster = new DaoMaster(db);daoSession = daoMaster.newSession();}

after that to use greendao just :

public DaoSession getDaoSession(){        return daoSession;}

And there you can have both contentProvider and greenDao. If you have not started your project yet then create the content provider manually and create the DaoMaster with the same code in here. Good Luck