Android: 如何将 return 巨大的字节数组作为 activity 的结果?

Android: How to return huge byte array as activity's result?

private void returnImage(byte[] array)
{
    Intent intent = new Intent();
    intent.putExtra(RETURNING_MESSAGE, array);
    setResult(RESULT_OK, intent);
    finish();
}

我通过这些回调获取了相机的字节数组

@Override
public void onClick(View v) {
    mCamera.takePicture(null, null, new Camera.PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            mCamera.release();
            returnImage(data);
        }
    });
}

在运行时我使用相机,但 activity 没有完成并且 Logcat 说 E/JavaBinder﹕ !!! FAILED BINDER TRANSACTION !!! 是图片大小的原因吗?我查看了一下,发现超过了200万字节。我需要使用我的自定义相机,但我无法 return 我的数据。

Is it caused by the size of the image?

是的。

I checked and found out that it's over 2 million bytes.

这大约是您的两倍 return。

I need to use my custom camera but I can't return my data.

或者:

  1. 不要让这些成为单独的活动,而是将它们作为一个 activity 中的单独片段,这样您就不必担心 Intent限制因素,或

  2. 使用其他东西,例如从静态数据成员到 byte[] 的(临时!)引用,允许同一应用程序中的多个活动共享数据,或者

  3. 如果 activity 调用 startActivityForResult() 在单独的应用程序中,使用 ContentProvider 将字节流回