Began slowly, to study rxJava.

There is a class Page

public class Page { public String value1; public String value2; ... public Page(String value1, String value2) { this.value1= value1; this.value2= value2; ... } } 

Then retrofit

 public static Retrofit getRetrofit(){ if(retrofit==null){ OkHttpClient.Builder builder = new OkHttpClient.Builder(); OkHttpClient okHttpClient = builder.build(); retrofit = new Retrofit.Builder() .baseUrl("http://www...") .addConverterFactory(PageAdapter.FACTORY) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(okHttpClient) .build(); } return retrofit; 

Interface

 public interface Service { @GET("myurl") Observable<Page> getData(); } 

Now, the crux of the matter. How to get value1, value2 ....? I use the mvp pattern.

Tried it like this (class MainPresenter)

 (Observable<Page>) NetworkClient.getRetrofit().create(Service.class) .getData() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(); 

Thank you in advance.

  • 2
    .subscribe (page -> println (page.value1)); - JuriySPb

1 answer 1

To get items from a stream, you must pass the subscriber parameters in the subscribe() method, in which at least the onNext method is onNext . In your case, you call the subscribe() method without a subscriber, and the onNext and onComplete methods onNext ignored. In the comment, @YuriSPb gave you a call to subscribe(Consumer<? super T> onNext) , that is, in this case the subscriber implements the subscribe() method and the subscriber provides a callback to handle the elements emitted by the stream.