Caused by: android.os.TransactionTooLargeException: data parcel size 1910660 bytes 问题原因与解决

当尝试从AActivity通过Intent传递一个包含大量图片URL的List<String>到BActivity时,遇到了android.os.TransactionTooLargeException。这个问题源于Binder交易缓冲区大小限制(1MB)。为了解决这个问题,可以考虑将数据保存到静态全局变量、本地文件或数据库,或者使用EventBus.postSticky来分批传递数据。避免一次性传输大量数据,确保应用的稳定运行。

从AActivity跳转BActivity通过intent.putExtra传递数据,结果报android.os.TransactionTooLargeException: data parcel size 551728 bytes错误,意思就是传输的数据过大,传递的是图片地址存储的 List< String >。准备到下个页面做预览功能

Caused by: android.os.TransactionTooLargeException: data parcel size 1910660 bytes 22 at 

android.os.BinderProxy.transactNative(Native Method) 23 at 

android.os.BinderProxy.transact(Binder.java:1154) 24 at 

android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:3676) 25 at 

android.app.Instrumentation.execStartActivity(Instrumentation.java:1705) 26 ... 15 more

 

源码
遇到问题我们首先看下TransactionTooLargeException这个类的源码注释,里面肯定有说明

通过以下源码注释内容可以了解到以下几点信息:

(1)通过Intent传递或者返回的数据是存放在一个叫做Binder transaction buffer的缓存区,这个缓冲 区的大小为1Mb(Android 28 Platform),当缓冲区不够用时就会抛出异常


(2)如果有多个数据传递同时进行,是共用缓冲区的1Mb,而不是每一个传输各分配1Mb缓存。这就有可能当多个传输同时进行时,数据大小小于1M还是抛出TransactionTooLargeException异常


(3)建议的解决方法就是尽可能减小传输的数据,至于具体要多效合上也没个具体的数值,也不可能知道,因为并发传输的数量不固定,但是至少可以肯定的是超过1M肯定会抛异常

/**
 * The Binder transaction failed because it was too large.
 * <p>
 * During a remote procedure call, the arguments and the return value of the call
 * are transferred as {@link Parcel} objects stored in the Binder transaction buffer.
 * If the arguments or the return value are too large to fit in the transaction buffer,
 * then the call will fail and {@link TransactionTooLargeException} will be thrown.
 * </p><p>
 * The Binder transaction buffer has a limited fixed size, currently 1Mb, which
 * is shared by all transactions in progress for the process.  Consequently this
 * exception can be thrown when there are many transactions in progress even when
 * most of the individual transactions are of moderate size.
 * </p><p>
 * There are two possible outcomes when a remote procedure call throws
 * {@link TransactionTooLargeException}.  Either the client was unable to send
 * its request to the service (most likely if the arguments were too large to fit in
 * the transaction buffer), or the service was unable to send its response back
 * to the client (most likely if the return value was too large to fit
 * in the transaction buffer).  It is not possible to tell which of these outcomes
 * actually occurred.  The client should assume that a partial failure occurred.
 * </p><p>
 * The key to avoiding {@link TransactionTooLargeException} is to keep all
 * transactions relatively small.  Try to minimize the amount of memory needed to create
 * a {@link Parcel} for the arguments and the return value of the remote procedure call.
 * Avoid transferring huge arrays of strings or large bitmaps.
 * If possible, try to break up big requests into smaller pieces.
 * </p><p>
 * If you are implementing a service, it may help to impose size or complexity
 * contraints on the queries that clients can perform.  For example, if the result set
 * could become large, then don't allow the client to request more than a few records
 * at a time.  Alternately, instead of returning all of the available data all at once,
 * return the essential information first and make the client ask for additional information
 * later as needed.
 * </p>
 */

public class TransactionTooLargeException extends RemoteException {
    public TransactionTooLargeException() {
        super();
    }
 
    public TransactionTooLargeException(String msg) {
        super(msg);
    }
}

解决方法
根据官方的建议就是减小传输的数据大小,或者拆分数据分次传输,但是如果数据量真的很大且需一次性传输有没解决方法呢,当然有

1.数据保存到static全局变量中

2.数据保存到本地存储中,比如本地文件或数据库,在目标Activity中再提取出来

3.通过EventBus.postSticky传递包含传递数据的粘性事件,在目标Activity中接收该事件提取数据(关于粘性事件参考Android EventBus Sticky Events粘性事件详解)

FATAL EXCEPTION: main Process: com.tplink.tpm5, PID: 15666 java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1131952 bytes Bundle stats: android:viewHierarchyState [size=1824] android:views [size=1776] androidx.lifecycle.BundlableSavedStateRegistry.key [size=1129376] androidx.lifecycle.internal.SavedStateHandlesProvider [size=1128012] androidx.lifecycle.ViewModelProvider.DefaultKey:com.tplink.apps.feature.advanced.heatmap.viewmodel.ConnectToWifiViewModel [size=375748] values [size=375644] androidx.lifecycle.ViewModelProvider.DefaultKey:com.tplink.apps.feature.advanced.heatmap.viewmodel.HeatmapOverviewViewModel [size=375748] values [size=375644] androidx.lifecycle.ViewModelProvider.DefaultKey:com.tplink.apps.feature.advanced.heatmap.viewmodel.DevicePlacementViewmodel [size=375748] values [size=375644] PersistableBundle stats: [null] at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:146) at android.os.Handler.handleCallback(Handler.java:973) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:282) at android.os.Looper.loop(Looper.java:387) at android.app.ActivityThread.main(ActivityThread.java:9500) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1005) Caused by: android.os.TransactionTooLargeException: data parcel size 1131952 bytes at android.os.BinderProxy.transactNative(Native Method) at android.os.BinderProxy.transact(BinderProxy.java:679) at android.app.IActivityClientController$Stub$Proxy.activityStopped(IActivityClientController.java:1545) at android.app.ActivityClient.activityStopped(ActivityClient.java:120) at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:135) ... 8 more
09-06
2025-10-30 19:03:55.611 16318-16318 MainActivity com.tencent.yolov5ncnn D decodeVideo: ------------/-1/2/content:/media/external/video/media/29/ORIGINAL/NONE/video/mp4/1895746813===============/-1/2/content://media/external/video/media/29/ORIGINAL/NONE/video/mp4/1895746813 2025-10-30 19:03:55.678 16318-16325 cent.yolov5ncnn com.tencent.yolov5ncnn I NativeAlloc concurrent mark compact GC freed 1145KB AllocSpace bytes, 3(60KB) LOS objects, 49% free, 1919KB/3839KB, paused 8.932ms,4.182ms total 57.817ms 2025-10-30 19:03:55.717 1938-1951 DatabaseUtils com...ndroid.providers.media.module E Writing exception to parcel java.lang.SecurityException: com.tencent.yolov5ncnn has no access to content://media/external/video/media/29 at com.android.providers.media.MediaProvider.enforceCallingPermissionInternal(MediaProvider.java:11734) at com.android.providers.media.MediaProvider.enforceCallingPermission(MediaProvider.java:11631) at com.android.providers.media.MediaProvider.checkAccess(MediaProvider.java:11755) at com.android.providers.media.MediaProvider.checkAccessForThumbnail(MediaProvider.java:9929) at com.android.providers.media.MediaProvider.ensureThumbnail(MediaProvider.java:9848) at com.android.providers.media.MediaProvider.openTypedAssetFileCommon(MediaProvider.java:9833) at com.android.providers.media.MediaProvider.openTypedAssetFile(MediaProvider.java:9773) at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:677) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:341) at android.os.Binder.execTransactInternal(Binder.java:1421) at android.os.Binder.execTransact(Binder.java:1365) 2025-10-30 19:03:55.722 16318-16318 MediaStore com.tencent.yolov5ncnn W Failed to obtain thumbnail for content://media/external/video/media/29 java.io.IOException: java.lang.SecurityException: com.tencent.yolov5ncnn has no access to content://media/external/video/media/29 at android.graphics.ImageDecoder$CallableSource.createImageDecoder(ImageDecoder.java:615) at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1858) at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1850) at android.content.ContentResolver.loadThumbnail(ContentResolver.java:4173) at android.content.ContentResolver.loadThumbnail(ContentResolver.java:4157) at android.provider.MediaStore$InternalThumbnails.getThumbnail(MediaStore.java:2932) at android.provider.MediaStore$Video$Thumbnails.getThumbnail(MediaStore.java:4612) at com.tencent.yolov5ncnn.MainActivity.decodeVideo(MainActivity.java:450) at com.tencent.yolov5ncnn.MainActivity.onActivityResult(MainActivity.java:237) at android.app.Activity.onActivityResult(Activity.java:7626) at android.app.Activity.internalDispatchActivityResult(Activity.java:9546) at android.app.Activity.dispatchActivityResult(Activity.java:9523) at android.app.ActivityThread.deliverResults(ActivityThread.java:6173) at android.app.ActivityThread.handleSendResult(ActivityThread.java:6223) at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:78) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:63) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2823) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loopOnce(Looper.java:248) at android.os.Looper.loop(Looper.java:338) at android.app.ActivityThread.main(ActivityThread.java:9067) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:932) Caused by: java.lang.SecurityException: com.tencent.yolov5ncnn has no access to content://media/external/video/media/29 at android.os.Parcel.createExceptionOrNull(Parcel.java:3340) at android.os.Parcel.createException(Parcel.java:3324) at android.os.Parcel.readException(Parcel.java:3307) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:201) at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:164) at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:814) at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2045) at android.content.ContentResolver.openTypedAssetFile(ContentResolver.java:1950) at android.content.ContentResolver.lambda$loadThumbnail$0(ContentResolver.java:4174) at android.content.ContentResolver$$ExternalSyntheticLambda0.call(D8$$SyntheticClass:0) at android.graphics.ImageDecoder$CallableSource.createImageDecoder(ImageDecoder.java:610) ... 26 more 2025-10-30 19:03:55.771 16318-16318 ThumbnailUtils com.tencent.yolov5ncnn W java.io.IOException: Failed to create thumbnail at android.media.ThumbnailUtils.createVideoThumbnail(ThumbnailUtils.java:391) at android.media.ThumbnailUtils.createVideoThumbnail(ThumbnailUtils.java:333) at com.tencent.yolov5ncnn.MainActivity.decodeVideo(MainActivity.java:454) at com.tencent.yolov5ncnn.MainActivity.onActivityResult(MainActivity.java:237) at android.app.Activity.onActivityResult(Activity.java:7626) at android.app.Activity.internalDispatchActivityResult(Activity.java:9546) at android.app.Activity.dispatchActivityResult(Activity.java:9523) at android.app.ActivityThread.deliverResults(ActivityThread.java:6173) at android.app.ActivityThread.handleSendResult(ActivityThread.java:6223) at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:78) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:63) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2823) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loopOnce(Looper.java:248) at android.os.Looper.loop(Looper.java:338) at android.app.ActivityThread.main(ActivityThread.java:9067) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:932) Caused by: java.lang.IllegalArgumentException: /storage/emulated/0/Download/20251011_112303.mp4 does not exist at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:255) at android.media.ThumbnailUtils.createVideoThumbnail(ThumbnailUtils.java:362) ... 21 more 2025-10-30 19:03:55.776 16318-16318 MainActivity com.tencent.yolov5ncnn D decodeVideo_address: ====================/storage/emulated/0/Download/20251011_112303.mp4-------/storage/emulated/0 2025-10-30 19:03:55.956 16318-16318 MediaCodecList com.tencent.yolov5ncnn D codecHandlesFormat: no format, so no extra checks 2025-10-30 19:03:55.958 16318-16318 MediaCodecList com.tencent.yolov5ncnn D codecHandlesFormat: no format, so no extra checks 2025-10-30 19:03:55.969 16318-16389 CCodec com.tencent.yolov5ncnn D allocate(c2.goldfish.h264.decoder) 2025-10-30 19:03:55.975 16318-16389 ApexCodecsLazy com.tencent.yolov5ncnn I Failed to load libcom.android.media.swcodec.apexcodecs.so: dlopen failed: library "libcom.android.media.swcodec.apexcodecs.so" not found 2025-10-30 19:03:55.975 16318-16389 Codec2Client com.tencent.yolov5ncnn I Available Codec2 services: "default" "software" 2025-10-30 19:03:55.985 16318-16389 CCodec com.tencent.yolov5ncnn I setting up 'default' as default (vendor) store 2025-10-30 19:03:56.003 16318-16389 CCodec com.tencent.yolov5ncnn I Created component [c2.goldfish.h264.decoder] for [c2.goldfish.h264.decoder] 2025-10-30 19:03:56.005 16318-16389 CCodecConfig com.tencent.yolov5ncnn D read media type: video/avc 2025-10-30 19:03:56.023 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D extent() != 1 for single value type: algo.buffers.max-count.values 2025-10-30 19:03:56.024 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D extent() != 1 for single value type: output.subscribed-indices.values 2025-10-30 19:03:56.025 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D extent() != 1 for single value type: input.buffers.allocator-ids.values 2025-10-30 19:03:56.026 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D extent() != 1 for single value type: output.buffers.allocator-ids.values 2025-10-30 19:03:56.027 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D extent() != 1 for single value type: algo.buffers.allocator-ids.values 2025-10-30 19:03:56.027 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D extent() != 1 for single value type: output.buffers.pool-ids.values 2025-10-30 19:03:56.028 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D extent() != 1 for single value type: algo.buffers.pool-ids.values 2025-10-30 19:03:56.033 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D ignored struct field coded.color-format.locations 2025-10-30 19:03:56.041 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D ignored struct field resources.needed.values 2025-10-30 19:03:56.041 16318-16389 CCodecConfig com.tencent.yolov5ncnn D ignoring local param raw.size (0xd2001800) as it is already supported 2025-10-30 19:03:56.041 16318-16389 CCodecConfig com.tencent.yolov5ncnn D ignoring local param default.color (0x5200180b) as it is already supported 2025-10-30 19:03:56.041 16318-16389 ReflectedParamUpdater com.tencent.yolov5ncnn D ignored struct field raw.hdr-static-info.mastering 2025-10-30 19:03:56.044 16318-16389 CCodecConfig com.tencent.yolov5ncnn I query failed after returning 12 values (BAD_INDEX) 2025-10-30 19:03:56.045 16318-16389 CCodecConfig com.tencent.yolov5ncnn D c2 config diff is Dict { c2::u32 coded.pl.level = 20496 c2::u32 coded.pl.profile = 20481 c2::u32 coded.vui.color.matrix = 0 c2::u32 coded.vui.color.primaries = 0 c2::u32 coded.vui.color.range = 2 c2::u32 coded.vui.color.transfer = 0 c2::u32 default.color.matrix = 0 c2::u32 default.color.primaries = 0 c2::u32 default.color.range = 0 c2::u32 default.color.transfer = 0 c2::u32 input.buffers.max-size.value = 6291456 c2::u32 input.delay.value = 0 string input.media-type.value = "video/avc" c2::u32 output.delay.value = 8 string output.media-type.value = "video/raw" c2::u32 raw.color.matrix = 0 c2::u32 raw.color.primaries = 0 c2::u32 raw.color.range = 2 c2::u32 raw.color.transfer = 0 c2::u32 raw.max-size.height = 240 c2::u32 raw.max-size.width = 320 c2::u32 raw.pixel-format.value = 35 c2::i32 raw.rotation.flip = 0 c2::i32 raw.rotation.value = 0 c2::u32 raw.sar.height = 1 c2::u32 raw.sar.width = 1 c2::u32 raw.size.height = 240 c2::u32 raw.size.width = 320 c2: 2025-10-30 19:03:56.046 16318-16389 ColorUtils com.tencent.yolov5ncnn W expected specified color aspects (2:0:0:0) 2025-10-30 19:03:56.080 16318-16318 TransactionExecutor com.tencent.yolov5ncnn E Failed to execute the transaction: tId:551909865 ClientTransaction{ tId:551909865 transactionItems=[ tId:551909865 TopResumedActivityChangeItem{mActivityToken=android.os.BinderProxy@7bd4eec,onTop=true} tId:551909865 Target activity: com.tencent.yolov5ncnn.MainActivity tId:551909865 ActivityResultItem{mActivityToken=android.os.BinderProxy@7bd4eec,resultInfoList=[ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/... flg=0x1 xflg=0x4 clip={text/uri-list {U(content)}} }}]} tId:551909865 Target activity: com.tencent.yolov5ncnn.MainActivity tId:551909865 ResumeActivityItem{mActivityToken=android.os.BinderProxy@7bd4eec,procState=2,isForward=false,shouldSendCompatFakeFocus=false} tId:551909865 Target activity: com.tencent.yolov5ncnn.MainActivity tId:551909865 ] tId:551909865 } 2025-10-30 19:03:56.081 16318-16318 AndroidRuntime com.tencent.yolov5ncnn D Shutting down VM 2025-10-30 19:03:56.082 16318-16318 AndroidRuntime com.tencent.yolov5ncnn E FATAL EXCEPTION: main Process: com.tencent.yolov5ncnn, PID: 16318 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/... flg=0x1 xflg=0x4 clip={text/uri-list {U(content)}} }} to activity {com.tencent.yolov5ncnn/com.tencent.yolov5ncnn.MainActivity}: java.lang.IllegalArgumentException: The surface has been released at android.app.ActivityThread.deliverResults(ActivityThread.java:6184) at android.app.ActivityThread.handleSendResult(ActivityThread.java:6223) at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:78) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:63) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2823) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loopOnce(Looper.java:248) at android.os.Looper.loop(Looper.java:338) at android.app.ActivityThread.main(ActivityThread.java:9067) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:932) Caused by: java.lang.IllegalArgumentException: The surface has been released at android.media.MediaCodec.native_configure(Native Method) at android.media.MediaCodec.configure(MediaCodec.java:2562) at android.media.MediaCodec.configure(MediaCodec.java:2422) at com.tencent.yolov5ncnn.MainActivity.decodeVideo(MainActivity.java:514) at com.tencent.yolov5ncnn.MainActivity.onActivityResult(MainActivity.java:237) at android.app.Activity.onActivityResult(Activity.java:7626) at android.app.Activity.internalDispatchActivityResult(Activity.java:9546) at android.app.Activity.dispatchActivityResult(Activity.java:9523) at android.app.ActivityThread.deliverResults(ActivityThread.java:6173) ... 14 more
10-31
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值