Async Task using RxJava2 in Android I have tried to create the async task using the RxJAVA2. The code is working fine. WHat enhancement can I do in this code?

private void createObservable(){


         progressDialog =new ProgressDialog(ProductActivityRx.this);
        progressDialog.setTitle("Data fetching...");
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();

        Observable&lt;List&lt;Product&gt;&gt; booksObservable =Observable.fromCallable(new Callable&lt;List&lt;Product&gt;&gt;() {
            @Override
            public List&lt;Product&gt; call() throws Exception {
                return getProductList();
            }
        }).doOnNext(new Consumer&lt;List&lt;Product&gt;&gt;() {
            @Override
            public void accept(List&lt;Product&gt; strings) throws Exception {
            }
        });

        productSubscription = booksObservable.
                subscribeOn(Schedulers.io()).
                observeOn(AndroidSchedulers.mainThread()).
                subscribe(new Consumer&lt;List&lt;Product&gt;&gt;() {
                    @Override
                    public void accept(List&lt;Product&gt; productList) throws Exception {

                        displayData(productList);
                    }
                });

    }


I am updating the UI in displayData().
in general, I believe it would be better if you included this in some sort of chain. What I mean here:


don't return void, rather an Observable
don't show the progress dialog in the function, rather delegate it to the part responsible for UI. Same with displayData()
where's the whole function called? What calls it? Where is it located, in an Activity?

doOnNext() can be gotten rid of - there's no action in here
Are you getting just one result at a time? I mean, is the function called perpetually on and on and on, and you just evaluate the result each time? Perhaps you could use Single or Maybe, which is better suited for single results.


Good luck and hope we'll both learn something along the way.