我是realm
数据库的新手,所以需要一些帮助。当我杀死我的应用程序然后再次返回应用程序时,我无法检索retrofit
中保存的数据。插入工作完美。这是我的代码:
在callJson方法中插入代码:
realm.beginTransaction();
realmCities = realm.copyToRealm(clientContactList);
realm.commitTransaction();
我正在记录时插入后的响应:
path : /data/data/com.xyz.da/files/default.realm
response from realm : E/Output: ClientContact = proxy[{clientName:A},{email:mit@email.com},{address:Palava},{contactPerson:Amit},{numberMobile:9930182464},{numberLandline:25123456},{groupName:B},{tumbnailColor:0}]ClientContact = proxy[{clientName:A1},{email:abc@email.com},{address:MBP},{contactPerson:John},{numberMobile:9876543210},{numberLandline:25123456},{groupName:B1},{tumbnailColor:0}]ClientContact = proxy[{clientName:A10},{email:abc@email.com},{address:MBP},{contactPerson:John},{numberMobile:9876543210},{numberLandline:25123456},{groupName:E2},{tumbnailColor:0}]
在onCreateView中,我这样做:这里当我杀了应用程序然后回来realmCities
列表为空,所以它再次点击callJson()
if(realmCities!=null && realmCities.size()>0){
Log.e("realmCities",""+realmCities.size());
}else{
callJSON();
}
答案 0 :(得分:3)
您已插入数据,但当应用重启时,您必须从数据库中获取数据
$ echo "((-225.2*7+30*6)/17 + (19^2)/9)" | awk -f calc.awk
((-225.2*7+30*6)/17 + (19^2)/9) = -42.0301
重新启动应用程序时,您必须从数据库中获取数据,如:
realm.beginTransaction();
realmCities = realm.copyToRealm(clientContactList);
realm.commitTransaction();
之后你必须检查条件
RealmResults<ClientContact> realmCities= realm.where(ClientContact.class).findAllAsync();
//fetching the data
realmCities.load();