我从活动MainActivity中的片段转到活动SetExperimentActivity,如下所示:
Intent myIntent = new Intent(getActivity(), SetExperimentActivity.class);
myIntent.putExtra(SetExperimentActivity.KEY_RESERVATION_END, reservation.getEndAsDate());
getActivity().startActivityForResult(myIntent, 0);
getActivity().overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
在MainActivity中,我有onActivityResult方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
this.intent = data;
}
在SetExperimentActivity中,我做了一些操作,并使用额外的parcelable重定向回MainActivity:
Intent myIntent = new Intent();
myIntent.putExtra(Constants.EXTRA_EQUIPMENT, equipment);
setResult(0, myIntent);
finish();
未调用onActivityResult
答案 0 :(得分:1)
在这种情况下,您应该使用startActivityForResult
,而不是startActivity
!请参阅Getting a Result from an Activity上提供的官方文档。
答案 1 :(得分:0)
startactivityforresult
方法,然后在第二个活动中填写数据后我们可以使用setresult(RESULT_OK,data);
然后在第一个活动中调用onactivityresult
后输入代码:< / p>
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == PICK_CONTACT_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The user picked a contact.
// The Intent's data Uri identifies which contact was selected.
// Do something with the contact here (bigger example below)
}
}
}