我有一个Activity FirstActivity.Java,它有一个调用startActivityForResult()的FragmentA.Java。 SecondActivity.Java调用finish()但是onSectivityResult被调用一次,因为FragmentA调用了在FragmentA中编写的startActivityForResult()。从来没有像SecondActivity.Java调用finish()。
FragmentA:
Intent popup = new Intent(getActivity(),
PopupActivity.class);
popup.putExtra(PopupActivity.EXTRA_URL, url + "&_resolve=popupResolve");
startActivityForResult(popup, 222);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 222){
if (resultCode == Activity.RESULT_OK) {
executeJS((Uri) data.getSerializableExtra(PopupActivity.EXTRA_RESOLVE));
}
}
}
SecondActivity:
Intent data = new Intent();
Uri uri = Uri.parse(mUrl);
data.putExtra(EXTRA_RESOLVE, uri);
setResult(Activity.RESULT_OK, data);
finish();
答案 0 :(得分:0)
当Fragment调用startActivityForResult()时,在完成下一个活动时,在第一个Activity中调用onActivityResult方法,而不是在片段中调用。