Android 未从IntentService调用Realm.Transaction.Callback的onSuccess
我正试图使用Android 未从IntentService调用Realm.Transaction.Callback的onSuccess,android,realm,Android,Realm,我正试图使用executeTransaction函数更新领域中的记录,但当我从IntentService调用这段代码时,在Ream.Transaction.Callback的成功调用copyToRealmOrUpdate后不会自动调用回调 final Realm realm = getRealm() ; realm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm r
executeTransaction
函数更新领域中的记录,但当我从IntentService
调用这段代码时,在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());
}
我正在使用IntentService
进行后台数据库操作,当我从Activity调用上述代码时,webservice调用onSuccess
被调用,但我真的不想按照要求从Activity调用它。我认为原因是您正在IntentService中执行异步事务,也许在结果准备好之前,IntentService就已经关闭了。在任何情况下都不需要异步事务,因为IntentService正在后台线程上运行
仅执行以下操作应是相同的:
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
// work
}
});
realm.close();
你的意思是我不需要从IntentService
调用它?你需要,但你不需要IntentService内部的异步事务。或者,您可以在不使用IntentService的情况下使用异步事务。有什么方法可以同时使用IntentService和异步事务吗