我正在为我的应用使用相机套件库。当我回到图片回调时,我将字节数组转换为位图并尝试将其传递给下一个活动,如下所示:
ab_capture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cameraView.captureImage(new CameraKitEventCallback<CameraKitImage>() {
@Override
public void callback(CameraKitImage cameraKitImage) {
byte[] jpeg = cameraKitImage.getJpeg();
Bitmap bitmap = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length);
Intent previewIntent = new Intent(ImageActivity.this, PreviewActivity.class);
previewIntent.putExtra("cam_image", bitmap);
startActivity(previewIntent); // implicit
finish();
}
});
}
});
但点击按钮后,应用程序崩溃,我收到此错误消息:
E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 3686928)
02-28 01:03:06.183 9579-9999/base.android.com.thumbsapp E/AndroidRuntime: FATAL EXCEPTION: CameraViewWorker
Process: base.android.com.thumbsapp, PID: 9579
java.lang.RuntimeException: Failure from system
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525)
at android.app.Activity.startActivityForResult(Activity.java:4226)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java:4185)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:732)
at android.app.Activity.startActivity(Activity.java:4509)
at android.app.Activity.startActivity(Activity.java:4477)
at base.android.com.thumbsapp.UI.Activities.ImageActivity$1$1.callback(ImageActivity.java:83)
at base.android.com.thumbsapp.UI.Activities.ImageActivity$1$1.callback(ImageActivity.java:75)
at com.wonderkiln.camerakit.CameraView$4.imageCaptured(CameraView.java:471)
at com.wonderkiln.camerakit.Camera1$5.onPictureTaken(Camera1.java:427)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1361)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: android.os.TransactionTooLargeException: data parcel size 3686928 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:622)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3197)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)
at android.app.Activity.startActivityForResult(Activity.java:4226)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java:4185)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:732)
at android.app.Activity.startActivity(Activity.java:4509)
at android.app.Activity.startActivity(Activity.java:4477)
at base.android.com.thumbsapp.UI.Activities.ImageActivity$1$1.callback(ImageActivity.java:83)
at base.android.com.thumbsapp.UI.Activities.ImageActivity$1$1.callback(ImageActivity.java:75)
at com.wonderkiln.camerakit.CameraView$4.imageCaptured(CameraView.java:471)
at com.wonderkiln.camerakit.Camera1$5.onPictureTaken(Camera1.java:427)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1361)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.os.HandlerThread.run(HandlerThread.java:61)
此错误仅发生在Nougat设备上。当我在Lollipop上运行时,没有错误,但它没有启动预览活动。
我需要帮助理解和解决此错误以及进入下一个活动的问题。感谢。
答案 0 :(得分:0)
此错误仅发生在Nougat设备上
它将在绝大多数Android设备上发生。
我需要帮助理解并解决此错误
由于Intent
额外费用较大,Bitmap
太大了。
最好的解决方案是在这里没有两个活动。让一个活动具有不断变化的UI,例如通过使用片段。
或者,小心地通过Bitmap
字段传递static
,确保尽快将该字段设置为null
,这样您就没有多久 - 内存泄漏。
答案 1 :(得分:0)
你永远不应该使用意图传递这些大数据。它会在大多数设备上崩溃而且设计得不好。
首先将文件存储到磁盘,然后将其路径设置为意图