How to return to Fragment thats call registerForActivityResult after back pressed

1.1k Views Asked by At

When I call mPickFromGalleryLauncher.launch(PICK_FROM_GALLERY_INPUT) gallery is opened. If in gallery I press back button application is closed.

How can I return to Fragment from gallery? Application use SingleActivity pattern with Android Navigation Component.

My Fragment:

class ImagesFragment : Fragment(R.layout.fragment_images) {

    private val mPickFromGalleryLauncher by uiLazy {
        registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
            // handle uri
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        pickFromGalleryButton.setOnClickListener {
            mPickFromGalleryLauncher.launch("image/*")
        }
    }

}
0

There are 0 best solutions below