I tried several ways to do this, each of which is not available.
First, I tried to add the Migration implementation to the room using the addMigrations method, but found that it only works when updating the database, but not when creating it.
Then I tried to pass the implementation of SQLiteOpenHelper to Room using the openHelperFactory method. But after creating a bunch of classes to get around package-level access modifiers at the package level, I gave up on this effort. I also tried to subclass Room FrameworkSQLiteOpenHelperFactory, but again, the access modifier at the package level of its constructor did not support this.
Finally, I created an IntentService to populate the data and called it from the onCreate method of my Application subclass. The approach works, but the upcoming fix for the tracker issue mentioned by Sinigami elsewhere on this page should be the best solution.
Darryl
[Added July 19, 2017]
The problem looks as if it resolved in Room 1.0.0. Alpha 5. In this release, a callback has been added to RoomDatabase, which allows code to be executed when creating the database. Take a look at:
https://developer.android.com/reference/android/arch/persistence/room/RoomDatabase.Callback.html
Darryl staflund
source share