Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap startActivityForResult using RxJava?

How do I start and receive the result from a Activity inside the same 'Reactive chain'? Is it possible to wrap the startActivityForResult and onActivityResult; if so how would I accomplish that?

like image 544
tomwassing Avatar asked Aug 21 '26 19:08

tomwassing


1 Answers

First create a wrapper class that holds the result and request codes, and the intent. Let's call it Result

You can create a PublishSubject field in your Activity class. Let's call it subject.

Then you just call subject.onNext(new Result(requestCode, resultCode, data)); inside your onActivityResult method.

And finally you chain the subject the way you would an observable to your RX chain using a flatMap or some other operator based on what you need.

Sorry for poor formatting, I'm on my phone.

like image 187
Vasili Fedotov Avatar answered Aug 24 '26 09:08

Vasili Fedotov