不能从IntentService调用Realm.Transaction.Callback的onSuccess

时间:2016-04-09 09:22:49

标签: android realm

我正在尝试使用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中调用它。

0 个答案:

没有答案