I am trying to create Android CameraX app where user can take a photo, apply some image processing effects and view the result, without a need to save it to disk. But for me, the most challenging part is to pass the image to another activity where it will be processed.
- I could create an Intent and attach the image using PutExtra(). But it would take too much memory and slow down the UI, since intent extras are not recommended to exceed 1 Mbyte. For example, 8MP photo would consume 24 Mb uncompressed and about 1.3 Mb in JPEG format.
- Share the image in public class properties - according to Android docs, it's not a reliable way to pass data directly between activities, because the system may create and destroy them at any time.
- Okay, let's capture the image into a file to and open it in our second activity. Or just call a built-in camera app to do so. It wouldn't be a problem for couple of images. But if user wants to capture 20-30 of them and more, it will cram the media folder and wear down the device storage.
Which is the best practice to pass image data between activities?