问题:在Fragment中使用startActivityForResult(intent, 1);然后在Activity中的onActivityResult(int requestCode, int resultCode, Intent data)方法中取到
requestCode
并不是1,而在Fragment中的onActivityResult方法却能获得正确的requestCode
解决:
通过搜索stackoverflow获得答案:
You are calling
startActivityForResult()
from your Fragment. When you do this, the requestCode is changed by the Activity that owns the Fragment.
If you want to get the correct requestCode in your activity try this:
Change:
startActivityForResult(intent, 1);
To:
getActivity().startActivityForResult(intent, 1);