I have an activity which allows me to take an image with the camera, and I want to send this image to the parent activity as an Intent extra. However, if I actually try to add the image to the intent, all of a sudden the finish() call never seems to do anything and my activity never closes.
Here’s some of my code:
public void onPictureTaken(byte[] imageData, Camera c)
{
if (imageData != null) {
// Send the result as a byte array
Intent intent = new Intent();
intent.putExtra("imagedata", imageData);
setResult(RESULT_OK, intent);
finish();
}
}
The odd thing is, if I comment out the putExtra() call then it all works properly (without the image, of course) and my activity closes and I hit the parent’s onActivityResult() callback. But if I leave the line in, then the activity never closes and the callback never fires.
I’ve tried putting more trivial things in the extras, like strings, and it’s all worked perfectly. putExtra() is allowed to take a byte array and I’ve even tried wrapping it up as a Bitmap and sending that, but it didn’t work either. The only thing I can think of is that I’m just not supposed to pass something that big into an Intent, in which case I guess I’ll just try writing it to a file instead. It’s just that writing is to a file should be slower than just passing the byte array reference around, which is why I’m trying to do it this way.
Any ideas? Thanks in advance 🙂
Phone: Samsung Galaxy S
API level: 7
You shouldn’t be including your image data within the Intent extras. See this thread for clarification. In a nutshell, keep your Intent extras as small as possible.
I would suggest storing your picture to the SD card, and passing the path to this file in your Intent.