0

I have a List with Bitmaps. I want to resize the bitmaps in the background thread, and call an another method with the list.

Flowable.fromIterable(imageList)
        .map(new Function<Bitmap, Bitmap>() {
            @Override
            public Bitmap apply(Bitmap bitmap) throws Exception {

                Bitmap resized = ImageUtils.getInstance().getResizedBitmap(bitmap,1200);

                return resized;
            }
        })
        .subscribeOn(Schedulers.io())
        .observeOn(Schedulers.io())
        .subscribeWith(
                //
        );

I want to get the result list (with all resized images) and handle errors. Which subscriber can do it?

Any suggestion?

1 Answer 1

1

The typical pattern for this is as follows:

Flowable.fromIterable(imageList)
    .map(new Function<Bitmap, Bitmap>() {
        @Override
        public Bitmap apply(Bitmap bitmap) throws Exception {

            Bitmap resized = ImageUtils.getInstance().getResizedBitmap(bitmap,1200);

            return resized;
        }
    })
    .toList()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribeWith(
        new DisposableSubscriber<List<Bitmap>>() { 
            // ...
        }
    );
Sign up to request clarification or add additional context in comments.

5 Comments

There is any option to retry the failed "apply" calls? Only the failed calls.
Why would the getResizedBitmap fail and how would a retry not fail it?
For example OutOfMemoryException.
How would you recover from such fatal error? Retrying with still not enough memory will keep the method crashing.
It's true in this case. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.