Junior — Middle
Why is using a Bitmap object inside a Bundle object not allowed in Android?
sobes.tech AI
Answer from AI
Using a Bitmap object inside a Bundle object in Android is not recommended and often unacceptable due to data size limitations that can be transmitted through a Bundle. Bitmap can occupy a significant amount of memory, and attempting to put it into a Bundle can lead to errors such as TransactionTooLargeException.
Bundles are intended for passing small and simple data (primitives, strings, Parcelable objects with small sizes). For passing images, it is better to use other approaches:
- Save the Bitmap to a temporary file and pass the file path through the Bundle.
- Use a Singleton or ViewModel to store the Bitmap.
- Pass images through databases or cache.
Thus, to avoid performance issues and errors, Bitmaps are not placed directly into Bundles.