在父活动中
Intent intent = new Intent(getApplicationContext(), yourChildActivity.class);
intent.putExtra("key", "value");
startActivityForResult(intent, ACTIVITY_CONSTANT);
在子活动中通过向父活动发送返回结果的方式进行通信。
Intent data = new Intent();
data.putExtra("key1", "value1");
data.putExtra("key2", "value2");
// Activity finished return ok, return the data
setResult(RESULT_OK, data);
finish();
在父活动中获取子活动的结果信息
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
if (data.hasExtra("key1") && data.hasExtra("key2")) {
Toast.makeText(
this,
"Your reult is : "data.getExtras().getString("key1") + " " + data.getExtras().getString("key2"),
Toast.LENGTH_SHORT).show();
}
}
}
finish()
方法。感谢您指出所需的内容。 - Paresh Mayani