我正在尝试使用Realm
功能更新executeTransaction
中的记录,但当我从IntentService
调用此代码时,onSuccess
的{{1}}不是调用Ream.Transaction.Callback
后自动调用。
copyToRealmOrUpdate
我正在使用final Realm realm = getRealm() ;
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
//some db operations and eventually calling
realm.
realm.copyToRealmOrUpdate(employeeList);
}
}, new Realm.Transaction.Callback() {
@Override
public void onSuccess() {
// this function never gets called if
//the whole function is called from IntentService
realm.close();
}
@Override
public void onError(Exception e) {
realm.close();
}
});
private RealmConfiguration initalizeRealmConfig(){
if(realmConfiguration == null)
return realmConfiguration = new RealmConfiguration.Builder(mContext)
.name(DB_NAME)
.schemaVersion(DB_VERSION)
.build();
else return realmConfiguration;
}
public Realm getRealm(){
return Realm.getInstance(initalizeRealmConfig());
}
进行后台数据库操作和webservice调用,当我调用Activity IntentService
上面的代码时会被调用,但我真的不想根据需要从Activity中调用它。