简体   繁体   中英

onActivityResult is not calling

public void cameraIntent(Context context)
    {
        Intent takingPictureCameraintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            ((AppCompatActivity)context).startActivityForResult(takingPictureCameraintent, REQUEST_CAMERA);

            }

    }

This is my onActivityResult():

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == SELECT_FILE)
                onSelectFromGalleryResult(data);
            else if (requestCode == REQUEST_CAMERA)
                onCaptureImageResult(this,data);
        }
    }

onActivityResult() is not called. What should I do?

onActivityResult will be called in the activity that you called startActivityForResult.

If you are doing this in your method "((AppCompatActivity)context)" your parameter should be an AppCompatActivity and not a Context.

For solving your problem, look where you are calling cameraIntent and what you are passing as parameter, it is in that activity that onActivityResult will be called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM