在activity A中startActivityForResult
在activity B中代码如下
@Override
protected void onPause() {
super.onPause();
Intent intent=new Intent();
intent.putExtra("currentSelectPhotoPath",dstList.get(currentSelectItem));
setResult(GroupPhotoListActivity.REQUSET_FROM_VIEWIMAGE, intent);
finish();
}
在activity A中,onActivityResult(int requestCode, int resultCode, Intent intent) 的intent总为null.
解决办法:
因为执行back键的时候,activity A很有可能已经start了,然后activity B 的onPause()还没执行,所以setResult并没有传入
所以将setResult在finish()中传入可以解决这个问题。
@Override
public void finish() {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.putExtra("currentSelectPhotoPath",dstList.get(currentSelectItem));
setResult(GroupPhotoListActivity.REQUSET_FROM_VIEWIMAGE, intent);
super.finish();
}
也可以修改onBackpressed()
参考如下链接:
http://stackoverflow.com/questions/10023969/result-not-set-in-onpause-using-setresult-when-pressing-the-back-button