I have tried various operators for iterating objects using map, concatMap,all but i am not able to remove element from my list.
Here is a piece of code:
Observable.fromIterable(selectedJobs)
.observeOn(AndroidSchedulers.mainThread()) // Added this from one answer in SO. but still no resolution.
.all(homeJob -> {
if (!homeJob.isCanCloseJob()) {
selectedJobs.remove(homeJob); // <- this is what causing Exception
//toast message
} else {
//do something
}
return true;
})
.subscribe(new SingleObserver<Boolean>() {
@Override
public void onSubscribe(Disposable disposable) {
}
@Override
public void onSuccess(Boolean aBoolean) {
baseRealm.executeTransaction(realm -> realm.copyToRealmOrUpdate(selectedJobs));
}
@Override
public void onError(Throwable throwable) {
AppLogger.e(tag, throwable.getMessage());
// throws Caused by: java.util.ConcurrentModificationException
}
});
All I want is to check for condition then remove object from list.