Realm-Android对象属性不保存

时间:2018-01-07 13:10:59

标签: android realm realm-mobile-platform

Realm数据库不保存数据。 我正在尝试保存对象数据,但是当最后一个阶段执行时,会保存一个AccessToken记录,但Account.accessToken仍为null。 帐户类

public class Account extends RealmObject implements Serializable {
    private AccessToken accessToken;

    public AccessToken setAccessToken(AccessToken accessToken) {
        return this.accessToken = accessToken;
    }
}

AccessToken类:

public class AccessToken extends RealmObject {
    private long expiration_date;

    private String access_token;
    public void setExpirationDate(long expiration_date) {
        this.expiration_date = expiration_date;
    }
    public void setAccessToken(String access_token) {
        this.access_token = access_token;
    }
}

领域保存数据代码:

public void changeAccountAccessToken(final Account account, final AccessToken srcAccessToken) {
    realm.executeTransaction(new Realm.Transaction() {
        @Override
        public void execute(Realm realm) {
            AccessToken accessToken = realm.createObject(AccessToken.class);
            accessToken.setAccessToken(srcAccessToken.getAccessToken());
            accessToken.setExpirationDate(srcAccessToken.getExpirationDate());
            account.setAccessToken(accessToken);
        }
    });
}

0 个答案:

没有答案