onNext
使用 RxJava 运算符时,我遇到了没有被调用的问题toList
。toList
在被调用之前,一切都完全按照我的预期工作。我在这里、这里和这里读到的东西似乎表明了onCompleted
没有被调用的问题,但我还是 RxJava 的新手,所以我不确定我需要在哪里调用它才能让它工作。
最令人困惑的是,我试图从谷歌的 Android 架构中遵循的架构似乎没有调用onCompleted
,它工作得很好。
Subscription subscription = mDataSource
// Get Observable<List<Location>> from SQLBrite database
.getLocations()
// Convert to Location object
.flatMap(new Func1<List<Location>, Observable<Location>>() {
@Override
public Observable<Location> call(List<Location> locations) {
return Observable.from(locations);
}
})
// Filter here
.filter(new Func1<Location, Boolean>() {
@Override
public Boolean call(Location location) {
return mPreferences.getUsesCustomLocations() || location.getId().length() <= 2;
}
})
// Convert Location object to String
.map(new Func1<Location, String>() {
@Override
public String call(Location location) {
return location.getTitle();
}
})
// Convert to Observable<List<String>, however using toList()
// causes onNext() to never get called
.toList()
.subscribeOn(mSchedulerProvider.computation())
.observeOn(mSchedulerProvider.ui())
.subscribe(new Observer<List<String>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(List<String> locations) {
processLocations(locations);
}
});
mSubscriptions.add(subscription);