VictorAlbertos / RxActivityResult

A reactive-tiny-badass-vindictive library to break with the OnActivityResult implementation as it breaks the observable chain.
Apache License 2.0
593 stars 72 forks source link

how to set requestCode ? #53

Closed yedajiang44 closed 4 years ago

yedajiang44 commented 6 years ago

the requestCode always 0;

Intent takePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

RxActivityResult.on(this).startIntent(takePhoto)
        .subscribe(result -> {
            Intent data = result.data();
            int resultCode = result.resultCode();
            // the requestCode using which the activity is started can be received here.
            int requestCode = result.requestCode();//why always requestCode= 0?

            if(requestCode == YourActivity.YOUR_REQUEST_CODE)
            {
                // Do Something
            }

            if (resultCode == RESULT_OK) {
                result.targetUI().showImage(data);
            } else {
                result.targetUI().printUserCanceled();
            }
        });
stari4ek commented 6 years ago

I have same issue. Current implementation does not support it:

https://github.com/VictorAlbertos/RxActivityResult/blob/c22870376b2b84eed5fa97cf2d185d486ac66b32/rx_activity_result/src/main/java/rx_activity_result2/HolderActivity.java#L57

And the only situation when it's propagated is negative case:

private static int FAILED_REQUEST_CODE = -909;

This is really strange why it's included in example

yedajiang44 commented 6 years ago

@stari4ek I don't know why is this,and the author doesn't seem to maintenance,

darylsze commented 4 years ago

@yedajiang44 hope this message won't come too late. by viewing this project code thoroughly, you may notice that each RxActivityResult creates a new activity and fragment internally and transparently. By doing the startActivityForResult under the hood, you / users never notice the extra page, but it handles onActivityForResult for you, and pass the callback out by listener.

by this approach, one can ensure that each request and result are composed together in its own tunnel, like VPN, that others won't never interfere inside.

therefore, you don't have to care the request code, but the result code only.