ReActiveAndroid
ReActiveAndroid is Android ORM based on popular library ActiveAndroid. Unfortunately, the author of the library stopped maintaining it, so I decided to continue maintain the library instead of him.
Installation
Add this to your app build.gradle:
implementation 'com.reactiveandroid:reactiveandroid:1.4.3'
Usage
Attention! Instant run must be disabled on first launch to to run this project correctly, as this project utilizes the ReActiveAndroid library, which to have issues with Instant Run.
Before we get started work with a database, we should to configure it, i.e. define the name and version. To do so, just create a new class and annotate it with the @Database
annotation:
@Database(name = "AppDatabase", version = 1)
public class AppDatabase {
}
Note: database name should be specified without '.db' extension.
After that, we needed to initialize the library in onCreate
method of the Application
class:
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
DatabaseConfig appDatabaseConfig = new DatabaseConfig.Builder(AppDatabase.class)
.build();
ReActiveAndroid.init(new ReActiveConfig.Builder(this)
.addDatabaseConfigs(appDatabaseConfig)
.build());
}
}
Don't forget to add your application class to AndroidManifest.xml
:
<application
android:name="com.sample.core.App"
...
Since ReActiveAndroid supports to multiple databases, you can add several configurations of databases:
ReActiveAndroid.init(new ReActiveConfig.Builder(this)
.addDatabaseConfigs(appDatabaseConfig1, appDatabaseConfig2, ...)
.build());