android - Chaining 2 different async operations that is dependant on the value of an observable -
hi i'm new rxjava , trying wrap head around concepts. need value api, , run 2 more queries api dependent on value.
i tried implementing way it's giving me networkonmainthreadexception. there way 'fork' stream, or understanding flawed? appreciated.
connectableobservable<value> getsomevaluestream = _api .somehttpasynctask() .map(parsejsonresponse) .subscribeon(schedulers.newthread()) .observeon(androidschedulers.mainthread()) .publish(); getsomevaluestream .flatmap(httpasynctask2stream) .subscribe(); getsomevaluestream .flatmap(httpasynctask3stream) .subscribe(); getsomevaluestream.connect();
my guess want io-scheduler network calls , not main thread. this:
.observeon(androidschedulers.mainthread())
should this:
.observeon(androidschedulers.io())
remember observeon
causes observable's emissions done on different schedulers, leads network calls executed on main thread (hence error).
if there no io-scheduler in android use appropriate one.
Comments
Post a Comment