首先需要用到函数有:
startActivityForResult;
public final void setResult(int resultCode, String data)
protected void onActivityResult(int requestCode, int resultCode, Intent data)
例如 A 到 B, 从 B 得到 A 的数据:
A 到 B
static final int RG_REQUEST = 0; //判断回调函数的值
Intent intent = new Intent();
intent.setClass(A.this, B.class);
startActivityForResult(intent,RG_REQUEST);
//在 B 中处理
Bundle bundle = new Bundle();
bundle.putString("DataKey", edittext.getText().toString());//给 bundle 写入数据
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
//最后在 A 的回调函数里面接收数据
if (requestCode == RG_REQUEST) {
if (resultCode == RESULT_CANCELED)
setTitle("Canceled...");
else if(resultCode == RESULT_OK) {
setTitle((String)data.getCharSequenceExtra("DataKey"));
}
}
//demo
http://download.csdn.net/detail/dannor2010/4898671