Pass Bitmap Data Between Activities in Android
I was making an application where I chose image file using browser intent and process it using OpenCV NDK. I decided to keep a different Activity for the OpenCV part and hence I had to pass the bitmap data from my main Activity to the OpenCV part activity. I had written an application before where I starting one intent from another activity. But I did not know how to pass arguments to the new activity. I looked up on Google and found out how to call another activity and then how to pass required data.
Start New Activity from Current Activity
Start New Acticity from Current Activity With Passing Required Data
putExtra() method is used to send extra data from one activity to another.
Articles related to Bitmap
Read/Write Bitmap to local storage
4 ways to save Bitmap to disk storage in Android. Follow the best practices and avoid Read/Writer permissions by leveraging Storage Access Framework.
How to blur a bitmap?
Use Renderscript to blur bitmaps with high performance. This article also talks about how to create a bitmap from the screen view and blur it to have amazing effects.
Extract Data In Other Activity
getIntent()
method returns the intent that started this activity.
getStringExtra()
retrieves extended data from the intent.
Now, it turns out that it’s not possible to pass Bitmap as extended data. It needs to be converted to byteArray
.
Pass Bitamp as Extended Data
Retrieve Bitmap in Other Activity
Well, that’s how I pass bitmap data between two activities. There are some better methods to do this such as passing fileURIs.
P.S. Working on Android now. Need to get better at layouts and designs.
Playing around with Android UI
Articles focusing on Android UI - playing around with ViewPagers, CoordinatorLayout, meaningful motions and animations, implementing difficult customized views, etc.