Sobes.tech
Junior — Middle

How can you include and pass a 5MB image in a Bundle object inside an application?

sobes.tech AI

Answer from AI

Passing an image of 5 MB size directly into a Bundle object is not recommended, as Bundle has size limitations (usually around 1 MB), and this can lead to TransactionTooLargeException errors.

Recommended approaches:

  1. Save the image to internal or external storage (file) and pass the file path (String) in the Bundle.

  2. If you need to pass it in memory, you can compress the image (for example, into JPEG with reduced quality) and pass it as byte[] through the Bundle, but for 5 MB this is risky.

Example of passing a file path:

Bundle bundle = new Bundle();
bundle.putString("image_path", "/storage/emulated/0/Pictures/image.jpg");

The receiver can then load the image from the file at this path.

Thus, it is better to avoid passing large binary data through the Bundle and use the file system or databases to store large objects.