android - Retrofit 2 sequential Requests using asynchronous network calls with retry -


i trying send network request api using retrofit, , when response, use part of response in call, used call, , rxjava suggested, have second request executed before first one

public interface channelrequest {      @post("authenticate_with_options")     @formurlencoded     observable<channel> getauthenticationchannel(@fieldmap map<string, string> params);       @post("check")     @formurlencoded     observable<channel> getauthenticationstatus(@fieldmap map<string, string> params); } 

ss

        observable<channel> call2 = mapi.getthechannel().getauthenticationstatus(constants.http.paramsauth);         observable.interval(3, timeunit.seconds).retry(3);         subscription subscription2 = call2                 .subscribeon(schedulers.io()) // optional if not wish override default behavior                 .observeon(androidschedulers.mainthread()).subscribe(new subscriber<channel>() {                       @override                     public void oncompleted() {                       }                      @override                     public void onerror(throwable e) {                          if (e instanceof httpexception) {                             httpexception response = (httpexception) e;                             int code = response.code();                         }                     }                      @override                     public void onnext(channel channel) {                          log.d("authstatus", "onresponse: " + channel.getchannel());                      }                 }); 

i not sure if have use rxjava anymore, best practice achieve ?

thanks

your code doesn't issue (as there 1 call api in example)

nevertheless, can @ operator flatmap call observable, result of previous call.

 mapi.getthechannel().getauthenticationstatus(constants.http.paramsauth)                      // use result previous call perform 1                      .flatmap(result -> mapi.getthechannel().getauthentificationchannel(result))                      .subscribeon(schedulers.io()) // optional if not wish override default behavior                      .observeon(androidschedulers.mainthread())                      .subscribe(); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -