Migration from ActiveAndroid

Step 1. Configure database

Since ReActiveAndroid supports to multiple databases, you can't configure the database through AndroidManifest.xml file. Therefore, delete all meta-data items related with ActiveAndroid.

To configure the database create a new class and annotate it with the @Database annotation:

@Database(name = "AppDatabase", version = 1)
public class AppDatabase {
}

After that you must specify database class in your models:

@Table(database = AppDatabase.class)
public class Note {

Step 2. Add primary key field to models

In ActiveAndroid primary key field was named "_id", but in the ReActiveAndroid named "id". So you must provide the migration to rename primary key column or just set custom column name:

@Table(name = "Notes", database = AppDatabase.class)
public class Note {

    @PrimaryKey("_id")
    private Long id;

    ...

}

Step 3. Initialize library

To start using the library you must initalize it 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());
    }

}

Step 4. Provide migrations

If your database schema is changed, you must provide migration to update old database scheme. Otherwise, all your tables will be deleted and recreated. To learn more about migrations, please see this page.

Other changes

The old syntax in ActiveAndroid build queries looked like this:

List<Note> notes = new Select().from(Note.class).execute();
Note note = new Select().from(Note.class).where("id=?", 1).where("title LIKE '?%'", "Hello").executeSingle();

The new syntax for creating queries looks like this:

List<Note> notes = Select.from(Note.class).fetch();
Note note = Select.from(Note.class).where("id=? AND title LIKE ?", 1, "Hello").fetchSingle();

For more information, please see this page.

results matching ""

    No results matching ""