I'm using Xamarin C# here.
I have an Android application, app A, and I would like to launch it from a second application, app B, passing some data into it. This will dictate which operations to perform and what data to return.
When app A is finished, I would like to return said data to app B.
Currently, app B launches app A via StartActivityForResult, and awaits the response with OnActivityResult:
PackageManager pm = PackageManager;
Intent intent = pm.GetLaunchIntentForPackage("Application.A");
intent.SetAction("Task_1");
Bundle bundle = new Bundle();
bundle.PutString("Activity", "BundleActivity");
StartActivityForResult(intent, (int)ActivityCode.Task1, bundle);
This correctly launches app A and allows me to determine that we need to do Task_1 (via the action, I've not tried the bundle).
When app A is done it performs the following:
var returnIntent = new Intent();
returnIntent.PutExtra("AppBData", the_data_obj);
SetResult(Result.Ok, returnIntent);
Finish();
This is detected by app B and caught in the OnActivityResult:
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
switch ((ActivityCode)requestCode)
{
case ActivityCode.Task1:
{
if (data != null)
{
Java.Lang.Object dataReturned = data.GetParcelableExtra("AppBData");
}
}
break;
default:
break;
}
}
}
but 'data' is always null.
Any ideas please?