I'm calling an API. When the app starts I need to get a token from the API to be able to do the other calls. The token is managed by a "token manager" inside the app. I'm using RxJava 2 and Retrofit 2 to manage the call.
When I launch the app, the Token Manager get the token and the Fragment gets the data. I expected the calls to be executed sequentially as both are using the same Retrofit client object injected with Dagger 2. But, in fact, the call to get data is executed before the call to get the token finishes, and as this call needs the token, the request fails.
Some people suggest to use a flatmap but I can't as the logic are managed at two different places in the app (the TokenManager class and the Fragment). How can I solve my issue?