您好我搜索了#34; onActivityResult()未调用"但是在花了好几天后我无法打电话给活动结果。
我在做什么: 我从活动中调用片段然后在片段上我从gallary获取图像并且它没有调用片段的onActivityResult。
请建议我如何解决这个问题。
活动类
myswitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
{
FragmentTransaction fragmentTransaction=getFragmentManager().beginTransaction();
CarPoolingSignUpFragment carPoolingSignUpFragment=new CarPoolingSignUpFragment();
fragmentTransaction.replace(R.id.carPoolingLoginFrameLayout,carPoolingSignUpFragment,"SignUp");
fragmentTransaction.commit();
}}
从片段中打开gallary
ignUpProPic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("daf", "ddddddd");
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
try {
startActivityForResult(i, RESULT_LOAD_IMAGE);
}catch (ActivityNotFoundException e){
e.printStackTrace();
Toast.makeText(getActivity(), "errrorr", Toast.LENGTH_SHORT).show();
}
片段中的onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("ActivityResult", "---");
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getActivity().getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
driverProPath = cursor.getString(columnIndex);
signUpProPic.setImageBitmap(BitmapFactory.decodeFile(driverProPath));}}
答案 0 :(得分:1)
您需要在fragment
onActivityResult
内拨打Activity
onActivityResult
。例如:
我的活动中的代码
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mFragment.onActivityResult(requestCode, resultCode, data);
}