This is a library that can help you to receive results from startActivityForResult()
as an Observable. You can use it in Activity or Fragment. It actullay call the startActivityForResult()
in a Headless-Fragment that attaching to your Activity(/Fragment). And publish the activity results in the Headless-Fragment's onActivityResult()
.
Supports only RxJava 2 now.
Example:
RxActivityResult.startActivityForResult(this, intent, REQUEST_CODE)
.subscribe(new Consumer<ActivityResult>() {
@Override
public void accept(@NonNull ActivityResult result) throws Exception {
if (result.isOk()) {
final Intent data = result.getData();
// DO SOME THING
}
}
});
See the sample for more detail.
- Add the JitPack repository to your
build.gradle
repositories:
repositories {
// ...
maven { url "https://jitpack.io" }
}
- Add the core dependency:
dependencies {
compile 'com.github.nekocode.rxactivityresult:rxactivityresult:{lastest-version}'
}
- (Optional) Add the below library if you need to support api 9 and later. Besides, if you already add support-v4 dependency, I will also suggest you to use this compact library, and then use the
RxActivityResultCompact
instead of theRxActivityResult
.
dependencies {
compile 'com.github.nekocode.rxactivityresult:rxactivityresult-compact:{lastest-version}'
}