Android – batch insert in realm

I decided to use realm for my project. I have read the document and can't understand how to import all mobile contacts into my realm database. Has anyone done this project before? Please help.

I used sugar ORM, which has a batch insertion option. Does realm have the same or a substitute?

This is what I have done so far:

package com.advisualinc.switchchat.Realm_DB;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;

/**
 * Created by Veeresh on 10/19/2015.
 */
public class R_ContactDB extends RealmObject {
    private String name;
    @PrimaryKey
    private String phone;
    private boolean matchedWithRecent;
    private int status;


    public R_ContactDB(String name, String phone, boolean matchedWithRecent, int   status)
    {
        this.name = name;
        this.phone = phone;
        this.matchedWithRecent = matchedWithRecent;
        this.status = status;
    }

    public R_ContactDB()
    {

    }

    public String getName() {
        return name;
    }

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

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public boolean isMatchedWithRecent() {
        return matchedWithRecent;
    }

    public void setMatchedWithRecent(boolean matchedWithRecent) {
        this.matchedWithRecent = matchedWithRecent;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}

resolvent:

Using realm does not need to be directly applicable to the batch inserts available in SQLite. It does not involve the overhead of query language

You can insert multiple objects through the real #copytorealm batch in a single write transaction. @ h_ 301_ 19 @ if you need to import JSON data, there is real#createorupdateallformjson (jsonarray)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>