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

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -