I am trying to return results to app1 from app2 but onActivityResults
not getting hit. I have tried both 'startActivityForResult' and new call back methods. Below are my codes.
Intent intent = new Intent();
intent.setComponent(new ComponentName(
"com.example.myapplication1",
"com.example.myapplication1.MainActivity"
));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
someActivityResultLauncher.launch(intent);
My Call back
ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
// There are no request codes
Intent data = result.getData();
results.setText(data.getStringExtra("TextValue"));
}
}
});
This is how I am returning data to app1 by setting results.
Intent result = new Intent();
result.putExtra("TextValue", ((EditText) findViewById(R.id.valueEntered)).getText().toString());
setResult(Activity.RESULT_OK, result);
finish();
Please guide what is wrong here. What other parts I need to check like intent-filters or activity defination in manifest.
I have tried this Open app with multiple inner Intents and wait for result but this needs to know activity details before hand. I want this to be generic.