android – 在Realm中批量插入

我决定将Realm用于我的项目.我已经阅读了文档,无法理解如何将所有手机联系人导入我的Realm数据库.
以前有人做过这种项目吗?请帮忙.

我使用了Sugar ORM,它有一个批量插入选项. Realm是否有相同或有替代品?

这是我到目前为止所做的事情:

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;
    }
}

解决方法:

使用Realm,不需要直接适用于SQLite中可用的批量插入的东西.不涉及查询语言的开销.

您可以通过单个写入事务中的Realm#copyToRealm批处理插入多个对象.
如果您需要导入JSON数据,则有Realm#createOrUpdateAllFromJson(JSONArray).

上一篇:error: ora-01034:oracle not available ora-27101:shared memory realm does not exist


下一篇:Realm for Android如何实际存储数据?