1

I'm developing an app that will handle calls from external applications, ask for some data to the user and return a small result. I already tried doing the interaction using intents and startActivityForResult.

The problem is that my app has an authentication process, and if I handle the call with the Login activity, and the user is already authenticated in my app, I will have to close the Login activity, open the Activity that asks for the data and loose my chance to return a result to the external app using setResult.

Is there any way to send the result back to the caller app from an activity other than the one that handles the intent-filter?

Also I was asked if it was possible to call my app on a different task, i.e. not having the activities of my app being part of the same process of the caller app.

1 Answer 1

2

You can use result-forwarding to do what you want. If ActivityA calls ActivityB with startActivityForResult() and ActivityB needs to start ActivityC to actually get the data, ActivityB can call startActivity() with an Intent containing Intent.FLAG_ACTIVITY_FORWARD_RESULT. When ActivityC finishes, the result is returned directly to ActivityA (assuming ActivityB has also finished). This answers the first part of your question.

In the second part of your question, you ask

... possible to call my app on a different task, i.e. not having the activities of my app being part of the same process of the caller app.

You used the terms "task" and "process" as if they were the same thing. In Android they are not the same thing.

  • A "process" is an Operating System process. In general, if ActivityA and ActivityB do not share the same Operating System user-id (ie: they are not from the same package, or from the same application), the 2 activities will run in different Operating System processes.

  • A "task" is a sequence of activities, that may come from completely different applications/packages and may run in completely different Operating System processes. If you want to use startActivityForResult() in order to pass data back from one activity to another, the 2 activities must run in the same task, although they do not need to run in the same Operating System process.

Sign up to request clarification or add additional context in comments.

2 Comments

First of all thank you for your quick answer and sorry for the mistake of process and task, I meant running in two different tasks. To implement that I was thinking on using a broadcast receiver to send it from my app, after work is done, and allow the caller to handle it.
You can, of course, communicate between activities by using broadcast Intents. That would work across different tasks. However, the user navigation with multiple tasks can be tricky, especially if the user presses the HOME button and tries to return to the application (there will be 2 tasks in the list of recent tasks) and the user may not know which is the correct one to return to. You just need to keep that in mind.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.