While you are only making API calls, you can use the Retrofit RxJava support by using Observables instead of callbacks and linking them together with Rx thread support. I mainly use the .flatmap () function to convert the result of one API call to another. In your case, it will look something like this:
First, I will use the version of Observable calls instead of those that have callbacks that will be:
Observable<LoginResponse> login(loginRequest); Observable<RoutesResponse> getRoutes(routesRequest);
After we have these two functions in our API, we can link them together with RxJava threads. Here is one without error checking, I write this on the go to show as a quick example:
public Observable<RoutesResponse> rxGetRoutes(loginRequest, routesRequest) { final YourAPI mAPI = YourApiProvider.getInstance(); return mAPI.login(loginRequest)
Now you can observe and subscribe to the returned Observable of this function as usual, after learning RxJava:
rxGetRoutes(loginReq, routesReq) .observeOn(
source share