How can I make one repeat call 2 after another?
I am reading about RxJava and I am already making my calls using RxJava, but I have not found a good example of using flatMaps.
Can someone explain how to do this with me?
I am trying to make these two calls, and after they are both made, I want to start a new job.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Retrofit retrofit = new Retrofit.Builder()
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl("http://api.openweathermap.org/data/2.5/")
.build();
WeatherService weatherService = retrofit.create(WeatherService.class);
final Observable<Weather> london = weatherService.getCurrent();
london.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Weather>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Weather weather) {
Log.i("WEATHER","Weather Name: " + weather.getName());
}
});
final Observable<Wind> windObservable = weatherService.getWind();
windObservable.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Wind>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Wind wind) {
Log.i("WEATHER","Wind: " + wind.getSpeed().toString());
}
});
}
}
source
share