How to pass object which contain Bitmap to another activity

烂漫一生 提交于 2019-12-05 11:58:53

Its not a great idea to pass Bitmap between two activities. You would get TransactionTooLargeException when you attempt to do so. Maximum limit for transaction data is around 1MB and Bitmap could easily overshoot it. This could lead to crash.

You can just use the URI that you are getting in onActivityResult() via following code:

Uri selectedImage = data.getData();

Pass this URI between the activities. You can then load image using the URI on-demand rather than transfering whole Bitmap object.

@SabaJafarzade Thank you pointing out, to reuse the Uri.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!