Search code examples
androidandroid-sqliteandroid-room

Room library can copy db from asset folder?


I have old project with Pre-loaded database in Assets folder. The project have SQLiteOpenHelper implemented for database operations. But now to update app I want to move my project to Room database library.

So my question is, Is there any method or feature available in Room library with I can use preloaded db file in app at runtime.

Or Is any way I can load db first and then from Room library I can directly execute queries on that db?


Solution

  • Is there any method or feature available in Room library with I can use preloaded db file in app at runtime.

    Starting with Room 2.2.0, RoomDatabase.Builder supports createFromAsset() and createFromFile() for setting up a database with pre-loaded initial content. See the documentation for more.