0

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.

vijay
  • 2,034
  • 3
  • 19
  • 38
  • 1
    Convert it to a Byte array before you add it to the intent, send it out, and decode. – Naveen Tamrakar Oct 22 '14 at 06:12
  • 1
    http://stackoverflow.com/questions/11010386/send-bitmap-using-intent-android – Naveen Tamrakar Oct 22 '14 at 06:12
  • @AnikIslamAbhi it takes a lot of time to save the image to sd card, which is irritating. – vijay Oct 22 '14 at 06:14
  • @NaveenTamrakar will the approach be fine with greater size images like 5MB ? As earlier depicted in the question, people suggest not to send greater size bitmap (not bitArray though) as intent data. – vijay Oct 22 '14 at 06:16

2 Answers2

1

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.

Rafael Skubisz
  • 460
  • 3
  • 9
  • No, I am capturing the image in activity A and loading it in activity B. Here caching won't make much sense to me as same image is not going to be loaded again. In activity A, I have camera integrated which would capture image and I need to show that image in activity B. – vijay Oct 22 '14 at 06:23
  • I dont know what phone you use, but doesnt using the camera save the image without your help? How do you call your intent? Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destination)); startActivityForResult(intent, REQUEST_IMAGE); – Rafael Skubisz Oct 22 '14 at 06:27
  • I have integrated camera within my app where I have override onPictureTaken(args), since I needed to attach a sticker to the captured image.Now, I call local function saveImageToExternalStorage() to save the image. But it takes sometimes.I wanted to replace it with intent.putExtra("imageArray",finalImage).will it be a good approach? I need the app to function well in HD devices like galaxy S5, Nexus 4,5 etc where image size is much higher. – vijay Oct 22 '14 at 06:33
1

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, ...);
Tapa Save
  • 4,769
  • 5
  • 32
  • 54