问题
Pretty much as the title says.
I want to launch my Android app, using ObjectBox, but I'd like the data to be prepopulated in the boxes.
Can I package both data.mdb and lock.mdb inside the app, from data I've created during development?
Or is there device specific stuff in there that will need to be generated on each specific device individually.
EDIT -
On checking how big my data.mdb file is it's HUGE!!! I am trying to store a dictionary of words. It has 370k 'rows' each containing a single word, and linking to another box which has a single value in. The file is 171Mb big!! That's outrageous!!!
I have it indexed, and have read that indexes make things large. Is this the case? Is there anything I can do about it?
回答1:
As to the original question: yes, you can ship your app with an initial data file. You can prepare an ObjectBox database with all the data you need and then grab the data.mdb from the db director (default name is "objectbox").
The BoxStoreBuilder
offers the overloaded method initialDbFile
this:
initialDbFile(java.io.File initialDbFile)
initialDbFile(Factory<java.io.InputStream> initialDbFileFactory)
Thus, you can either provide a File
or an InputStream
.
来源:https://stackoverflow.com/questions/51735068/can-i-ship-an-android-app-with-a-pre-populated-objectbox-db-in-it