Reputation: 2034
I am trying to access an image in another activity (say B) which is being captured in activity(say A). Now here, I have two options:
1. Save to sd card and then access in activity B through the filepath.
But, time taken to save is higher in some cases, probably because of higher
image size.
2. Send the bit array through intent.putExtra("imageArray" , data) and access it
in activity B through getIntent(). But on surfing net, I found sending bigger
bitmap of 1MB or more is a bad practise but didn't find anything with regards to
bitarray.
Can someone suggest me which option is better ? And is sending a bitmap of greater size as bitArray to another activity a bad practise ?
My requirement is : time lag between two activities A and B should be minimum. Also, image should be loaded in activity B in no time.
Thanks in advance.
Upvotes: 0
Views: 224
Reputation: 4857
Also you can use global variables in Application space (singleton).
Example:
public class YourApplication extends Application
{
private static YourApplication singleton;
Bitmap bitmap; // or any type, byte array
....
public static YourApplication getInstance()
{
return singleton;
}
}
...
in another class you can set and get this variable 'bitmap':
YourApplication.getInstance().bitmap = ....; // in Activity A
or
... = YourApplication.getInstance().bitmap; // in Activity B
or use inside another method
....( ..., YourApplication.getInstance().bitmap, ...);
Upvotes: 1
Reputation: 470
If you load the image both in activity A and activity B by using a URL you can use ion - https://github.com/koush/ion. It helps you show pictures using a URL and it caches your image, so that loading it again happens instantly, just send the url from activity A to activity B.
If you use the phone camera to capture a image I would say that saving it is the better way to go, if your gonna want to send many pictures at once in the future the second option will be bad.
Upvotes: 1