在我的存储库中,我有一个Retrofit调用,返回一个Observable>
public Observable<List<Task>> getTasks() {
final List<Task> tasks = new ArrayList<>();
return TaskService.networkCall().getTasks()
.flatMap(new Func1<Response<ResponseObject>, Observable<List<Task>>>() {
@Override
public Observable<List<Task>> call(Response<ResponseObject> responseObjectResponse) {
List<Task> response = responseObjectResponse.body().getTasksResponse();
tasks.addAll(response);
return Observable.just(tasks); // this have the list of tasks - I checked
}
});
当我尝试在我的viewModel中添加并返回List时遇到的问题:
public List<Task> getTaskList() {
final List<Task> cache = new ArrayList<>();
mSubscription.add(mDataManager.getTasks()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<Task>>() {
@Override
public void call(List<Task> tasks) { // List<Task> has data
cache.addAll(tasks); // List<Task> cache is always 0 size
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
}
}));
我做错了什么?