RxImagePicker not calling completion if orientation changes when taking image

437 Views Asked by At

I'm using RxImagePicker to take photos in my portrait-only-forced app:

RxImagePicker.with(getActivity()).requestImage(Sources.CAMERA).subscribe(new Action1<Uri>() {
        @Override
        public void call(Uri uri) {
            RxImageConverters.uriToBitmap(getActivity(), uri).subscribe(new Action1<Bitmap>() {
                @Override
                public void call(final Bitmap bitmap) {
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //i take over here if we ever get here...
                        }
                    });
                }
            });
        }
    });

If I take a picture without rotating the device, it works (although the image is rotated but that's another issue). However, if I take a picture in landscape orientation, uriToBitmap is never called. It's not my activity or fragment being restarted, as everything's state is preserved inside my app.

What am I doing wrong?

2

There are 2 best solutions below

0
Can Poyrazoğlu On BEST ANSWER

It turned out to be something not-so-extraordinary.

I've simply forgot to update to the latest version and was using a few months old version of the library, which had the fix for the problem that I'm facing.

I've updated to the latest version and the problem went away.

0
m.ostroverkhov On

Acording to sources, RxImagePicker uses PublishSubject to communicate uri notifications to the client. Picker starts hidden activity, and that activity issues onCompleted() in it's onDestroy() callback. That callback is called on activity recreation in response to orientation change. Because Subject is Observable, it obeys to Observable contract, which states there should be no further notifications after onCompleted(), hence onNext() notifications following onCompleted() are ignored. There is another issue: onCompleted() is called twice when image is successfully picked. Seems like there is no workaround, possible solutions:

  • Fork library and fix aforementioned issues on your own

  • File issue on github so author can address them

  • Roll out your own solution ( best IMO)