An open API service indexing awesome lists of open source software.

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

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
```