We often need to transfer images between activities.
Well there are many methods to transfer images.
- You can make the image into a Base64 String and pass it as String argument extra in a bundle between activities
- You can save it to a disc and read it in the other activity.
Well, these methods will always work, but what could be the fastest and efficient solution.
Here is it. Just make a singleton class and set the image in a variable in it.
How to Do?
I am having a singleton class named “BitmapSingleton” which has a image variable with a setter and getter method.
For sending images between activities…
From activity A -> BitmapSingleton.getInstance().setBitmap(bitmap);
From activity B -> BitmapSingleton.getInstance().getBitmap(bitmap);
After you use it, you should do BitmapSingleton.getInstance().setBitmap(null); in activity B.
Please leave your valuable comments below this post.