ObjectBox is a mobile database that persists objects simple and super fast. It lets you avoid many repetitive tasks and offers a simple interface to your data.
Gradle plugin and code generation
In order to use ObjectBox in your Android project, you need to add its Gradle plugin and Android library:
apply plugin: 'com.android.application'
apply plugin: 'io.objectbox'
Then model your entities and make your project, for example using “Build > Make Project” in Android Studio.
Once you have defined at least one entity and successfully built your project, you can start using ObjectBox in your Android project.
The following core classes are the essential interface to ObjectBox:
MyObjectBox: Generated based on your entity classes, MyObjectBox supplies a builder to set up a BoxStore for your app.
BoxStore: The entry point for using ObjectBox. BoxStore is your direct interface to the database and manages Boxes.
Box: A box persists and queries for entities. For each entity, there is a Box (supplied by BoxStore).
Entities: Use ObjectBox annotations to mark your object classes as persistable.
Finally, the basic steps to initialize the core ObjectBox classes:
// do this once, for example in your Application class
boxStore = MyObjectBox.builder().androidContext(App.this).build();
// do this in your activities/fragments to get hold of a Box
notesBox = ((App) getApplication()).getBoxStore().boxFor(Note.class);
The example assumes a Note entity exists. With its Box ( notesBox object), we can call the persistence operation for this specific entity.
Have an app with greenDAO? DaoCompat is for you!
DaoCompat is an compatibility layer that gives you an greenDAO like API for ObjectBox. This makes switching simple. Have a look at the example. Docs will follow, contact us if you have any questions!