onActivityResult(活动类)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == 1 && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
Data.desiredaddress = cursor.getString(columnIndex);
cursor.close();
}
super.onActivityResult(requestCode, resultCode, data);
}
}
onActivityResult(片段类)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 2 && resultCode == Activity.RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor1 = getActivity().getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor1.moveToFirst();
int columnIndex = cursor1.getColumnIndex(filePathColumn[0]);
Data.desiredaddress = cursor1.getString(columnIndex);
cursor1.close();
}
}
我的问题:
有人可以帮助我。
谢谢。
答案 0 :(得分:0)
在我经历了一些其他问题后,我发现原因是因为即使我从片段类调用onActivityResult,onActivityResult(父活动)也不会被忽略。
感谢@Aswin Rajendiran的想法。
这是进一步解释的链接:https://stackoverflow.com/a/16434914/4148255