https://github.com/patrick-doyle/android-rxintents
RxWrapper around startActivityForResult and managing the callbacks
https://github.com/patrick-doyle/android-rxintents
Last synced: 3 months ago
JSON representation
RxWrapper around startActivityForResult and managing the callbacks
- Host: GitHub
- URL: https://github.com/patrick-doyle/android-rxintents
- Owner: patrick-doyle
- Created: 2016-07-09T22:31:27.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-30T14:25:02.000Z (almost 9 years ago)
- Last Synced: 2025-04-11T22:06:55.348Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 171 KB
- Stars: 7
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Android RxJava wrapper for startActivityForResult
## RxIntent
#### Setup
Add to root build.gradle
```groovy
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
```
In your module build.gradle file add to the dependencies block
```groovy
dependencies {
compile "com.twistedequations.rx:rx-intent:1.0.0"
}
```
If its giving an error about not finding a jar file use `com.twistedequations.rx:rx-intent:1.0.0@aar` instead
## Usage
To listen for onActivityForResultEvents
```java
Observable observable = RxIntent.observeActivityForResult(activity, requestCode);
```
The Observable will emit one event when the result activity returns and then
will finish with an onCompleteEvent.
To start the activity for result use the `RxIntent.startActivityForResult(activity, intent, options, requestCode)` method.
this will start the activity and any `RxIntent.observeActivityForResult(activity, requestCode)` observables will emit the result of the callback as log as the
request codes are the same.
Use `RxIntent.startAndObserveActivityForResult(activity, intent, options, requestCode)` method to start the activity
To Handle activities being recreated while in the next activity is visible you can merge the results of `observeActivityForResult()` with a `startAndObserveActivityForResult()`
call into a single stream.
```java
final Observable rxIntentObservable = RxIntent.observeActivityForResult(RxIntentActivity.this, REQUEST_CODE);
final Observable result = RxView.clicks(view)
.flatMap(new Func1>() {
@Override
public Observable call(Void aVoid) {
return RxIntent.startAndObserveActivityForResult(RxIntentActivity.this, intent, REQUEST_CODE);
}
});
final Observable rxIntentResultObservable = Observable.merge(rxIntentObservable, result);
//handle the events from the rxIntentResultObservable
```