Hey, so in the case of the camera image, I create a file where I'll store the image and use FileProvider to get a uri for it. Then when you call the launch() method on the ActivityResultContracts.TakePicture() contract takes the uri pointing to where you want the captured image stored. So once the contract returns successfully you know the uri now points to the image that was just taken. I just store the uri in the fragment at that stage as its only used in that scope and i can either persist it, display it or do nothing with it.

In the case of the Gallery it's a bit different as it returns the uris in the contract callback.

I hope this helps, if you're getting images I maybe would use the built-in contracts rather than a custom one but it obviously depends on whether they meet your needs.

Software developer, Northern Ireland