Activity A:
int tag = 0;
startActivityForResult(new Intent(getApplication(), LoreAddActivity.class).putExtra("tag1", tag), 100);
@Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
super.onActivityResult(arg0, arg1, arg2);
if(arg1==RESULT_OK){
switch (arg0) {
case 100:
tag2 = arg2.getIntExtra("tag2", 0);
break;
default:
break;
}
}
}
Activity B:
int tag = getIntent().getIntExtra("tag1",0);
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putInt("tag2", tag);
intent.putExtras(bundle);
setResult(RESULT_OK, intent);
finish();
There may be something wrong in the intent. Try new Intent(XXX.this,LoreAddActivity.class);
The application object returned by getApplication also inherits context, so you can use it like this. But if the source is not explicitly specified, then when receiving the callback, that is, setResult, B does not know where the intent comes from. The above is my understanding and is for reference only. If there are any errors, please point them out
As long as Activity A is returned, onActivityResult will be executed. You can use Log or debug to confirm where onActivityResult is not executed
What are the startup modes of the two activities?
This sentence uses getApplication. Activity starts in standard mode by default. An Activity started in this mode will enter the task stack of the Activity that started it by default. The Context obtained by the getApplication method does not contain task stack information. Therefore, it is best not to use getApplication when starting an Activity, and replace it with the Context of the Activity.