I am a newbie in RxJava programming and I want to ask about how to process each iteration of list that I have from a retrofit call. Basically what I want to do is:
Here is my code so far
Observable<List<Appointment>> callAppointments = appointmentServiceRx.getService().getConfirmedAppointments(user_id);
callAppointments.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatMapIterable(apps -> apps)
.concatMap(app -> getPatientById(app)
.doOnNext(this::addPatientNames)
.map(patient -> app)
).concatMap(app -> getSubserviceById(app)
.doOnNext(this::addSubserviceNames)
.map(subservice -> app)
).toList()
.subscribe(res -> doStuff(),
throwable -> showThrowable());
Please help and thank you in advance...
The observeOn(AndroidSchedulers.mainThread())
call right at the beginning forces all subsequent operators to run on the main thread, which then throws NetworkOnMainThreadException
.
Try moving this call to the last point before the subscribe
:
// ...
.observeOn(AndroidSchedulers.mainThread())
.subscribe(res -> doStuff(),
throwable -> showThrowable());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.