Search code examples
androidandroid-intentdeep-linkingonactivityresult

Call Activity.setResult() from activity which is already finished


I am trying to implement deep linking in my android app.

My use case is when a user clicks on deep linking url and then selects my app for payment then my application's ActivityA gets opened (launcher activity) and then after finishing ActivityA, from there my ActivityB gets opened and from there, after finishing ActivityB, ActivityC gets opened. Now in ActivityC after making the payment I want to call setResult() method in order to send payment data back to the previous app.

My question is as ActivityA is already finished how can I call setResult() in order to send response back?

Also I am finishing ActivityA and ActivityB because when user presses back button I don't want my user to go back to these activities.


Solution

  • Intent.FLAG_ACTIVITY_FORWARD_RESULT is the intent flag you need to apply when you are navigating between ActivityA to ActivityB and then to ActivityC. From docs:

    If set and this intent is being used to launch a new activity from an existing one, then the reply target of the existing activity will be transfered to the new activity. This way the new activity can call setResult(int) and have that result sent back to the reply target of the original activity.