我得到了一个TransactionTooLargeException。无法复制的。文件里说

The Binder transaction failed because it was too large. During a remote procedure call, the arguments and the return value of the call are transferred as 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 TransactionTooLargeException will be thrown. ... There are two possible outcomes when a remote procedure call throws 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). ...

在某个地方,我传递或接收的参数超出了未知的限制。在哪里?

stacktrace没有显示任何有用的东西:

java.lang.RuntimeException: Adding window failed
at android.view.ViewRootImpl.setView(ViewRootImpl.java:548)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:406)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:320)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:152)
at android.view.Window$LocalWindowManager.addView(Window.java:557)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2897)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4977)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.TransactionTooLargeException
at android.os.BinderProxy.transact(Native Method)
at android.view.IWindowSession$Stub$Proxy.add(IWindowSession.java:569)
at android.view.ViewRootImpl.setView(ViewRootImpl.java:538)
... 16 more
android.os.TransactionTooLargeException
at android.os.BinderProxy.transact(Native Method)
at android.view.IWindowSession$Stub$Proxy.add(IWindowSession.java:569)
at android.view.ViewRootImpl.setView(ViewRootImpl.java:538)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:406)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:320)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:152)
at android.view.Window$LocalWindowManager.addView(Window.java:557)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2897)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4977)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

这似乎和观点有关?这与远程过程调用有什么关系?

可能重要的是:Android版本:4.0.3,设备:HTC One X


当前回答

在我的情况下,我得到TransactionTooLargeException作为二次崩溃后本机库崩溃与SIGSEGV。本机库崩溃没有报告,所以我只收到TransactionTooLargeException。

其他回答

我遇到过这个问题,我发现当服务和应用程序之间交换大量数据时(这涉及传输大量的缩略图)。实际上数据大小在500kb左右,IPC事务缓冲区大小设置为1024KB。我不确定为什么它超过了事务缓冲区。

当您通过intent extras传递大量数据时,也会发生这种情况

当您在应用程序中遇到此异常时,请分析您的代码。

您是否在服务和应用程序之间交换了大量数据? 使用intent共享海量数据,(例如用户从gallery共享中选择大量文件按share,所选文件的uri将使用intent传输) 从服务接收位图文件 等待android返回大量数据(例如,当用户安装了大量应用程序时,getInstalledApplications()) 使用applyBatch()处理大量未决操作

当你得到这个异常时如何处理

如果可能的话,将大操作拆分为小块,例如,调用applyBatch()时不要使用1000个操作,而是每个操作使用100个。

服务和应用之间不交换大数据(>1MB)

我不知道怎么做,但是,不要查询android,它可以返回巨大的数据:-)

另一个可能的原因是:

我有一个活动,开始自己在onResume()!这会导致大量的事务,导致手机(Galaxy S2)完全冻结(没有ANR或任何东西),然后硬重置,这本身就是一个巨大的错误。

看看在其他手机上用这个代码会发生什么会很有趣:

class MyActivity extends Activity
{
  // ...
  @Override
  void onResume()
  {
     super.onResume()
     startActivity(new Intent(this, MyActivity.class));
  }
}

我不是说你应该使用那个代码。

我在卸载另一个应用程序正在进行IPC调用的应用程序时得到了这个错误。

一个假设是;由于“服务”应用程序因为卸载而消失,一些传输缓冲区可能已经被填满,导致这个错误,因为没有东西不再从缓冲区中“弹出东西”。

如果这是你的情况,这个问题可能没什么好担心的。

尝试使用EventBus或ContentProvider之类的解决方案。

如果你在同一个进程中(通常你所有的活动都是),尽量使用EventBus,因为在进程中数据交换不需要一个缓冲,所以你不需要担心你的数据太大。(你可以只使用方法调用来传递数据,而EventBus隐藏了丑陋的东西) 细节如下:

// one side
startActivity(intentNotTooLarge);
EventBus.getDefault().post(new FooEvent(theHugeData));

// the other side
@Subscribe public void handleData(FooEvent event) { /* get and handle data */ }

如果Intent的双方不在同一个进程中,可以尝试一些ContentProvider。


看到TransactionTooLargeException

Binder事务失败,因为它太大了。 在远程过程调用期间,调用的参数和返回值作为Parcel对象传输,存储在Binder事务缓冲区中。如果参数或返回值太大,无法放入事务缓冲区,则调用将失败,并抛出TransactionTooLargeException。

一个解决方案是应用程序将数组列表(或任何导致问题的对象)写入文件系统,然后通过Intent将该文件的引用(例如,文件名/路径)传递给IntentService,然后让IntentService检索文件内容并将其转换回数组列表。

当IntentService处理完文件后,它应该要么删除它,要么通过Local Broadcast将指令传递回应用程序以删除它创建的文件(传递回提供给它的相同文件引用)。

要了解更多信息,请参阅我对这个相关问题的回答。