Friday, 21 September 2018

rxjava + retrofit - How to wait and get the result of first observable in android?

I've recently started learning retrofit and rxjava. I'm looking for any ideas on how to wait ang get the result of first observable. Basically, I want to apply it on a simple login. The first api call is getting the server time. The second api call will wait the result of the first call (which is the server time) and utilize it.

                Retrofit retrofit = RetrofitClient.getRetrofitClient();
                LocalServerInterface apiInterface = retrofit.create(LocalServerInterface .class);

                Observable<ServerTime> timeObservable = retrofit
                        .create(LocalServerInterface .class)
                        .getTime()
                        .subscribeOn(Schedulers.newThread())
                        .observeOn(AndroidSchedulers.mainThread());

                Observable<ServerNetwork> serverNetworkObservable = retrofit
                        .create(LocalServerInterface .class)
                        .getNetworks(//valuefromapicall1, anothervalue)
                        .subscribeOn(Schedulers.newThread())
                        .observeOn(AndroidSchedulers.mainThread());

Now, I'm stuck right here. On second observable, particularly on getNetworks method, I wanted to use what I got from first observable. Any ideas?

EDIT:

I wanted to process first the result of call 1 before supplying it to the api call 2. Is it possible?



from rxjava + retrofit - How to wait and get the result of first observable in android?

No comments:

Post a Comment