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!
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).
Returning results from external apps to App Inventor apps
The AndExplorer example at https://appinventor.mit.edu/explore/content/using-activity-starter.html 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.
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.
Result
Returns the result from the activity. ResultName
Specifies the name that will be used to retrieve a result from the activity. ResultType
Returns the MIME type from the activity. ResultUri
Returns the URI from the activity.
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.
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!