How can I bundle a Realm database file with my app to deploy with installation

女生的网名这么多〃 提交于 2019-12-05 01:18:20

问题


I have a data set of around 50k records which I want to put in a Realm database. I am unsure of how can I make this DB in Realm and bundle it with the App so that the file can reside from the very start (installation) in the device.


回答1:


You can put a Realm file in your assets folder and copy it the first time you open the app. There is an example on how to do that here: https://github.com/realm/realm-java/blob/master/examples/migrationExample/src/main/java/io/realm/examples/realmmigrationexample/MigrationExampleActivity.java#L57

You can then use SharedPreferencs/another Realm or similar to save a boolean to indicate that the Realm file has been copied.

Right now we don't have any API working outside Android, but one way to create a prepopulated Database is to make a small app that does it, run that that app on an emulator and then use ADB to pull the database: How to view my Realm file in the Realm Browser?



来源:https://stackoverflow.com/questions/35933804/how-can-i-bundle-a-realm-database-file-with-my-app-to-deploy-with-installation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!