How can an Activity get a result from an ActivityResultContract if there is an third intermediate Activity involved?

Viewed 20

I am migrating from the old startActivityForResult(Intent) code to the new Activity Result API (using ActivityResultContract).

In the old way of doing things, Activity A can start Activity B, which can in turn start Activity C with

intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);

which will cause Activity B to be deleted from the back stack and for the result to be sent directly to Activity A. That works, the question is how does achieve the same thing using the new Activity Result API? (I'm using androidx.activity:activity:1.5.1)

Currently, my Activity A does not receive any result from Activity C.

1 Answers

The FLAG_ACTIVITY_FORWARD_RESULT does still work with the new Activity Result API. The problem I had is that you cannot also continue to implement the old onActivityResult() method as it will override the new Result API (and return a resultCode of -1).

This means that when migrating an Activity to use the Activity Result API, you must migrate all Intent launches within the Activity, you cannot use both API's at the same time.

Related