Communicating between 2 AppInventor Apps

Hi there AI2 community!

I'm facing an issue in communicating between two apps created using AI2. I'll try to explain what I want to achieve in as much detail as possible:

I have two apps, namely First App and Second App. Both the apps are created using AI2.
Here's what I want to achieve:

  1. I want to pass a value from the First App to the Second App while opening it.
  2. Then I want to return a value from the Second App back to the First App when the Second App is closed.

For this I used the Activity Starter and followed the steps mentioned in this guide: Using the Activity Starter Component

By following the steps mentioned in the doc, I was successfully able to open the Second App from the First App and was also able to pass a value to it successfully. However my problem lies in point 2, i.e. I'm unable to pass a return value from the Second App back to the First App by following the method stated in the doc. For some reason, it always returns an empty string, whereas it is supposed to be returning a legitimate value.

Any help will be greatly appreciated!

Below are the screenshots of my blocks, and I've also provided the .aia files for both the apps. Thanks!

First App:
First_App.aia (3.6 KB)

Second App:
Second_App.aia (3.1 KB)

the return value will be received in the ActivityStarter and not during Screen1.Initialize

Returning results from App Inventor apps to external apps

When the App Inventor app that you started finishes (more technically, when the current screen closes with CloseScreen), it will signal onActivityResult() to the external app that started it. The App Inventor app can pass back a text string value by using Close Screen With Plain Text. That value will be available to the external app through the returned Intent as Intent.getStringExtra(APP_INVENTOR_RESULT).


1 Like

I can't help but feel there might be more to this.


Returning results from external apps to App Inventor apps

The AndExplorer example at using Classic App inventor shows how external apps can make results available as properties of the Activity Starter when the app terminates. In the case of AndExplorer, the properties were ResultType and ResultUri. To know this information about AndExplorer, you’d need to find documentation for AndExplorer or see examples of Android code that uses it.

In general when your external app finishes and returns an intent to the App Inventor app that started it, the value of Intent.type() will be available as the ActivityStarter.ResultType property. Similarly, the will be the value of Intent.getDataString() will be available as the ResultUri property.

You can also pass back other information in the intent. Choose a name (Java String) for the result and have the App Inventor apps set that name to be the ResultName property of the activity starter. To return a desired value from your external app in an intent, use Intent.putextra(chosenResultName, desiredValue). When your external app finishes, the App Inventor ActivityStarter.AfterActivity() event will be signalled, and the result parameter to event handler will be the desired value. That same desired value will also be available as the Activity Starter’s Result property. The desired value must be a string, and you can return only one value using this method.

But I don't see anything in the Activity Starter's attributes after return.

Is it possible I need to pull in an Activity Starter component in the subroutine Project to act as go-between for passing values back to the calling Project?

There are so many Activity Starter attributes hanging around.

Thank you for your inputs, @Taifun and @ABG!

Is there a way to achieve this using the blocks currently available in the Activity Starter component?

In the very doc, it is mentioned that

App Inventor screens are activities, so you can use the Activity Starter to start other App Inventor apps. The Hello Purr example at the top of this page shows how to do this. This is basically how App Inventor’s multiple screen apps work.
To pass a startup text value to the App Inventor app you are starting with the Activity Starter, ise EXTRAS to set the KEY property to the string APP_INVENTOR_START and set the VALUE Property to the text you want to pass. The other app can then retrieve this value with Get Start Plain Text. To return a value from the other app, use Close Screen With Plain Text.

But for some reason that dosen't seem to work ):

I do not see you using any of these properties

Returns the result from the activity.
Specifies the name that will be used to retrieve a result from the activity.
Returns the MIME type from the activity.
Returns the URI from the activity.


I found a working sample at

The calling app:
(after return)
Suma.aia (2.6 KB)

The called app:
Calcula.aia (2.9 KB)

I had trouble figuring out why the author was fiddling around with directories and files, until I realized it was for the purpose of identifying the required Package Name needed to call this app from an Activity Starter.

So aside from being in Spanish, this works.

Wow that worked! Thank you very much @ABG!

Like @Taifun mentioned, I hadn't set the the ResultName to APP_INVENTOR_RESULT which is why I was unable to retrieve it. After adding this block, it works like a charm!

Thank you very much once again! (:

P.S. This would be a good place for an AI2 Helper block for that piece of magic text being loaded into the Activity Starter.

On the other hand, lack of it acts like a child lock to keep out the unwary.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.