Android的:某些意图额外prevent活动结束 [英] Android: Certain intent extras prevent activity finish
问题描述
我有一个活动,让我拍摄图像的相机,我想这个图像发送到父活动作为一个额外的意向。但是,如果我真的尝试将图像添加到意向,一下子的完成()
电话似乎永远不会做任何事情,我的活动永远不会关闭。
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.
下面是我的一些code的:
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();
}
}
奇怪的是,如果我注释掉 putExtra()
通话,然后这一切工作正常(无图像,当然)和我的活动关闭,我打父母的的onActivityResult()
回调。但是,如果我在离开该行,那么活动从来没有关闭,回调永远不会触发。
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.
我试过把更多琐碎的事情中的演员,像琴弦,这一切都完美。 putExtra()
被允许携带一个字节数组,我甚至试过包装它作为一个位图和发送的,但它也不能工作。我能想到的唯一的事情是,我只是不应该的东西,大的传入一个Intent,在这种情况下,我想我就尝试写入文件来代替。这只是写作是一个文件应该不仅仅是传递字节数组引用各地,这就是为什么我试图做这种方式速度较慢。
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 :)
电话:三星Galaxy S
API级别:7
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.
我会建议您存储照片的SD卡,并通过此文件路径在你的意图。
I would suggest storing your picture to the SD card, and passing the path to this file in your Intent.
这篇关于Android的:某些意图额外prevent活动结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!