Skip to content

ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to save and retrieve SQLite database records without ever writing a single SQL statement. Each database record is wrapped neatly into a class with methods like save() and delete().

Notifications You must be signed in to change notification settings

rahman22/AndroidActiveOrmAppDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 

Repository files navigation

Overview

Using the ActiveAndroid ORM makes managing client-side models extremely easy in simple cases. For more advanced or custom cases, you can use SQLiteOpenHelper to manage the database communication directly. But for simple model mapping from JSON, ActiveAndroid keeps things simple.

ActiveAndroid works like any Object Relational Mapper by mapping java classes to database tables and mapping java class member variables to the table columns. Through this process, each table maps to a Java model and the columns in the table represent the respective data fields. Similarly, each row in the database represents a particular object. This allows us to create, modify, delete and query our SQLite database using model objects instead of raw SQL.

Installation

In Android Studio, you can setup ActiveAndroid via Gradle in app/build.gradle:

repositories {

jcenter()

maven { 

url "https://oss.sonatype.org/content/repositories/snapshots/"

}

}
#### dependencies 

{

compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.android.support:appcompat-v7:22.2.1'

compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'

}

Database Config

        <meta-data
            android:name="AA_DB_NAME"
            android:value="subjectdb.db" />
        <meta-data
            android:name="AA_DB_VERSION"
            android:value="1" />

Table Structure

package com.example.thedeveloper.androidactiveormappdemo.models;

import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;

/**
 * Created by The Developer on 5/17/2017.
 */
@Table(name = "subjects")
public class SubjectList extends Model {

    @Column(name = "name")
    private String nameSubject;
    @Column(name = "description")
    private String descriptionSubject;

    public String getNameSubject() {
        return nameSubject;
    }

    public void setNameSubject(String nameSubject) {
        this.nameSubject = nameSubject;
    }

    public String getDescriptionSubject() {
        return descriptionSubject;
    }

    public void setDescriptionSubject(String descriptionSubject) {
        this.descriptionSubject = descriptionSubject;
    }
}

Activeandroid ORM Config

import android.app.Application;

import com.activeandroid.ActiveAndroid;

/**
 * Created by The Developer on 5/17/2017.
 */

public class Configs extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        ActiveAndroid.initialize(this);
    }
}

Crud App Screenshot

About

ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to save and retrieve SQLite database records without ever writing a single SQL statement. Each database record is wrapped neatly into a class with methods like save() and delete().

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages