我正在尝试将数据从子活动发送给父母。但不知何故, onActivityResult(..) 没有被调用。这是代码
家长活动
selectedText.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
Intent intent = new Intent(Parents.this,Child.class);
startActivityForResult(intent, 1);
}
return true;
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 1:
if (resultCode == RESULT_OK) {
if (data.hasExtra("selText")) {
selectedText.setText(data.getExtras().getString(
"selText"));
}
break;
}
}
子活动:我可以看到 setResult() 中设置的选定值。但是在子活动完成后,它不会回到父活动。
textListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int myItemInt,
long arg3) {
selectedFromList =(String) (textListView.getItemAtPosition(myItemInt));
Intent data = new Intent();
data.putExtra("selText", selectedFromList);
setResult(RESULT_OK,data);
finish();
}
});