Monday, 31 July 2017

Android DBFlow impelmentation



1) Add dependencies

def dbflow_version = "3.1.1"

dependencies {

apt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"

}

2) add to project gradel file

dependencies
{
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}

3) in applicatin class

public class AppController extends Application {

    @Override    public void onCreate() {
        super.onCreate();

        // initialize dbflow database        FlowManager.init(new FlowConfig.Builder(this).build());

    }

}

4) example database class (MyDatabase.java)

@Database(name = MyDatabase.NAME, version = MyDatabase.VERSION)
public class MyDatabase {
    public static final String NAME = "MyDataBase";
    public static final int VERSION = 1;
}

5) example table class (MediaItem.java)


@Table(database = MyDatabase.class)
public class MediaItem extends BaseModel {

    @PrimaryKey(autoincrement = true)
    long id;
    @Column
    String name;
    @Column
    String number;
    @Column
    String isActive;
    @Column
    String percentage;

    public MediaItem() {
    }

    @Override
    public String toString() {
        return "Numbers{" +
                "id=" + id +
                ",name='" + name + '\'' +
                ",number='" + number + '\'' +
                ",isActive='" + isActive + '\'' +
                ",percentage='" + percentage + '\'' +
                '}';
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getIsActive() {
        return isActive;
    }

    public void setIsActive(String isActive) {
        this.isActive = isActive;
    }

    public String getPercentage() {
        return percentage;
    }

    public void setPercentage(String percentage) {
        this.percentage = percentage;
    }
}



No comments:

Post a Comment

Run/install/debug Android applications over Wi-Fi ?

Open Teminal/cmd --------------- Below steps is for Android 10 or lower Step 1 - Connect the device via USB and make sure debugging is work...