我使用以下代码在活动之间传递数据:
ActivityOne.class
Intent mIntent = new Intent(getBaseContext(), ActivityTwo.class);
mIntent.putExtra("test", test_value);
startActivityForResult(mIntent, 0);
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
Log.i(TAG, "Result: "+resultCode); // OK
final String test_value = data.getExtras().getString("test"); // fails here since data is null
Log.i(TAG, "Test: "+test_value);
}
ActivityTwo.class
@Override
protected void onStart() {
super.onStart();
...
setResult(result); // pass the result back to ActivityOne
finish(); // yes, I close it immediately after start ;)
那么,我应该如何正确地将ActivityOne中的Intent数据(test_value
)从ActivityOne传递到ActivityTwo(这部分工作正常)然后再返回ActivityOne(这部分不起作用,{{1} } data
是onActivityResult
)?
答案 0 :(得分:1)
你需要传回意图。
尝试:
setResult(result, getIntent());
这会将启动Activity2(即在Activity1中创建)的原始意图发送回Activity1