Tofasio
Tofasio

Reputation: 425

Observable seems to not call onNext after a while

I'm using RxAndroid library to process a list of items using subscriber / observable pattern. My problem is that, when an item is processed, there is a progress bar that needs to be updated. But after processing 16 items, it seems that the observable is not calling onNext method until the rest of the items( 90) are processed and then calls 90 times onNext method. Why is this happening? can this be a memory issue?

Code below.

Subscriber:

public void startSingleRecognition(int id, int position) {
    mAdapter.updateItemProgress(0, position);
    Uri imageUri = Uri.parse(getHpCard(id).getUrlImage());
    final int[] i = {0};
    mSubscription = mRecognitionUtils
            .getRecognitionObservable(imageUri, configurations)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                    abbyResult -> mAdapter.updateItemProgress(++i[0], position),
                    e -> e.printStackTrace(),
                    () ->  mAdapter.updateItemProgress(-1, position));

}

Observable:

public Observable<AbbyResult> getRecognitionObservable(Uri imageUri,
        ArrayList<Configuration> configurations) {
    return Observable.from(configurations)
            .flatMap(
                    configuration -> Observable.just(recognize(imageUri, configuration, this)));
}

The method recognize does hard work processing images, my first thought was that this method is consuming a lot of memory and the observable cannot deliver the processed item to the subscriber until all method calls are done. But I'm not really sure, can anyone confirm this?

Thanks!

Upvotes: 1

Views: 291

Answers (1)

Tofasio
Tofasio

Reputation: 425

Well, I think I have solved it! The issue was using flatMap instead of concatMap. Here it is well explained: http://fernandocejas.com/2015/01/11/rxjava-observable-tranformation-concatmap-vs-flatmap/

Upvotes: 1

Related Questions