OnActivityResult in the dialog fragment

I take a photo from a fragment of the dialogue. And also I need something likestartActivityForResult(takePictureIntent, actionCode);

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
        switch (requestCode) {
            case SELECT_PHOTO:
                getActivity();
                if (resultCode == Activity.RESULT_OK) {
                    Uri selectedImage = imageReturnedIntent.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]);

                    setPic();
                }
                break;
            case ACTION_TAKE_PHOTO_B: {
                getActivity();
                if (resultCode == Activity.RESULT_OK) {
                    handleBigCameraPhoto();

                }
                break;
            }
        }   
    }

Bu this method is not called. Is there any method like this that can be used in a dialog fragment

+4
source share
1 answer

try like this:

to get started with the snippet:

getActivity().startActivityForResult(intent, code);

to return the result to the fragment:

in your parent activity (fragment call operation):

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    fragmentObject
            .onActivityResult(requestCode, resultCode, data);
}
+17
source

Source: https://habr.com/ru/post/1532819/


All Articles