Skip to content
This repository has been archived by the owner on Aug 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #40 from lkopocinski/2.x
Browse files Browse the repository at this point in the history
Forward Throwable to onError() when ActivityNotFoundException thrown
  • Loading branch information
VictorAlbertos authored Apr 18, 2017
2 parents 366e1fb + 4622b07 commit 6ec8b16
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/app/OnPreResultActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected void onCreate(Bundle savedInstanceState) {

startPreForResult.setOnClickListener(v ->
RxActivityResult.on(this)
.startIntent(new Intent(this, FirstActivity.class), (resultCode, data) ->
.startIntent(new Intent(this, FirstActivity.class), (resultCode, requestCode, data) ->
Observable.just(Ignore.Get)
.map(_I -> data.putExtra(EXTRA_PRE, "Do whatever you want with the data, but not with the UI")))
.subscribe(result -> {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/SampleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void camera() {
} else {
result.targetUI().printUserCanceled();
}
});
}, Throwable::printStackTrace);
}

private void showImage(Intent data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package rx_activity_result2;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
Expand Down Expand Up @@ -52,7 +53,13 @@ protected void onCreate(Bundle savedInstanceState) {
if (requestIntentSender.getOptions() == null) startIntentSender(requestIntentSender);
else startIntentSenderWithOptions(requestIntentSender);
} else {
startActivityForResult(request.intent(), 0);
try {
startActivityForResult(request.intent(), 0);
} catch (ActivityNotFoundException e) {
if (onResult != null) {
onResult.error(e);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

interface OnResult extends Serializable {
void response(int requestCode, int resultCode, @Nullable Intent data);
void error(Throwable throwable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public void response(int requestCode, int resultCode, Intent data) {
subject.onNext(new Result<>(activity, requestCode, resultCode, data));
subject.onComplete();
}

@Override
public void error(Throwable throwable) {
subject.onError(throwable);
}
};
}

Expand All @@ -141,6 +146,11 @@ public void response(int requestCode, int resultCode, Intent data) {
//If code reaches this point it means some other activity has been stacked as a secondary process.
//Do nothing until the current activity be the target activity to get the associated fragment
}

@Override
public void error(Throwable throwable) {
subject.onError(throwable);
}
};
}

Expand Down

0 comments on commit 6ec8b16

Please sign in to comment.