A1
Intent intent = new Intent(MainActivity.this, SecondActivity.class); startActivityForResult(intent, 1);
@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode){ case 1:{ if(resultCode==RESULT_OK){ String val=data.getStringExtra("key_data_return"); Log.w("MainActivity","return val="+val); } }break; default:{ }; } }
A2启动后,设置intent值 再finish杀死
Intent intent = new Intent(); intent.putExtra("key_data_return", "val_return"); setResult(RESULT_OK, intent); finish();