如何将Realm数据库文件与我的应用程序捆绑在一起以进行安装部署 [英] How can I bundle a Realm database file with my app to deploy with installation

查看:75
本文介绍了如何将Realm数据库文件与我的应用程序捆绑在一起以进行安装部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大约50k记录的数据集,我想将其放入Realm数据库中.我不确定如何在Realm中创建此数据库并将其与App捆绑在一起,以便文件可以从一开始(安装)就驻留在设备中.

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.

推荐答案

您可以将Realm文件放入资产文件夹中,并在首次打开应用程序时将其复制.这里有一个有关如何执行此操作的示例: https://github.com/realm/realm-java/blob/master/examples/migrationExample/src/main/java/io/realm/examples/realmmigrationexample/MigrationExampleActivity.java#L57

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

然后您可以使用SharedPreferencs/另一个Realm或类似的域来保存一个布尔值,以指示该Realm文件已被复制.

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

现在,我们在Android之外还没有任何API可以使用,但是创建预填充数据库的一种方法是制作一个小型应用程序,然后在模拟器上运行该应用程序,然后使用ADB提取数据库: 如何在领域浏览器?

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?

这篇关于如何将Realm数据库文件与我的应用程序捆绑在一起以进行安装部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆