Android - launch another application to get the result

I have two applications: A and B.

From A, I run B for the result using the following code:

Intent fmIntent = getPackageManager().getLaunchIntentForPackage("com.example.B");
fmIntent.putExtra("hello", "world");
startActivityForResult(fmIntent, REQUEST_TEST);

From B, I do the following:

getIntent().putExtra("completed", true);
setResult(RESULT_OK, getIntent());
finish();

If I do this for activities in one application, it works as expected.

However, since it has two different applications, I get an empty intent without data and invalid result code. How do I edit the above to ensure that one intention is supported throughout?

+5
source share
2 answers

"Android onActivityResult, !". :

Intent myIntent = new Intent();
myIntent.setClassName("com.example.B", "com.example.B.ActivityB");
startActivityForResult(myIntent, 600);

.

+3

setFlags(0) , getLaunchIntentForPackage:

Intent fmIntent = getPackageManager().getLaunchIntentForPackage("com.example.B");
fmIntent.setFlags(0);
fmIntent.putExtra("hello", "world");
startActivityForResult(fmIntent, REQUEST_TEST);
0

All Articles