[英]android.os.TransactionTooLargeException thrown randomly
I am seeing quite a few error reports from one of my live apps, the caused is this exception: 我看到来自我的一个实时应用程序的相当多的错误报告,导致这个异常:
java.lang.RuntimeException: Adding window failed
at android.view.ViewRootImpl.setView(ViewRootImpl.java:513)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2852)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: android.os.TransactionTooLargeException
at android.os.BinderProxy.transact(Binder.java)
at android.view.IWindowSession$Stub$Proxy.addToDisplay(IWindowSession.java:683)
at android.view.ViewRootImpl.setView(ViewRootImpl.java:502)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2852)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(NativeStart.java)
From what I've read here , I believe the cause may be down to a too large Parcelable
I am adding to an Intent
extras. 从我在这里读到的,我相信原因可能是一个太大的Parcelable
我正在添加一个Intent
附加功能。 I am currently passing an Object from one Activity to another, in that Objects writeToParcel
method I am saving a JSON String which ranges in size from 1000 - 1500 characters in length. 我目前正在将一个Object从一个Activity传递给另一个Activity,其中对象writeToParcel
方法我正在保存一个JSON字符串,其长度范围为1000-1500个字符。 Could this be the cause? 这可能是原因吗?
Whilst testing the app I sometimes notice the UI lags as though it is low on memory, freezes and then force closes. 在测试应用程序时,我有时会注意到UI滞后,好像内存不足,冻结然后强制关闭。
Would it be better to pass the Object from one Activity to another using static variables or could this be caused by something else entirely? 使用静态变量将Object从一个Activity传递到另一个Activity会不会更好?或者这可能是完全由其他东西引起的?
Thanks 谢谢
Yes, this can very well be caused by a too large Parcelable, too large object graph to be sent as a Parcelable to be exact. 是的,这很可能是由于一个太大的Parcelable,一个太大的对象图形被精确地发送为Parcelable引起的。 In my experience you're better off using java serialization if you're transferring large graph and that is pretty much the opposite of the advice you'll get elsewhere on SO and in general. 根据我的经验,如果您正在转移大型图表,那么最好使用Java序列化,这与您在其他地方获得的建议完全相反。 To be fair it's better than using Parcelable via Parceler lib, I've never used pure Parcelable. 公平地说,它比通过Parceler lib使用Parcelable更好,我从未使用过纯Parcelable。 For more details see my blog post on this topic. 有关更多详细信息,请参阅我关于此主题的博文 。
according What to do on TransactionTooLargeException : 根据TransactionTooLargeException做什么 :
This can occur, when you pass lot of data through intent extras 当您通过intent extras传递大量数据时,可能会发生这种情况
If possible, split the big operation in to small chunks, for example, instead of calling applyBatch() with 1000 operations, call it with 100 each. 如果可能,将大操作拆分为小块,例如,而不是使用1000次操作调用applyBatch(),每次调用100。
Do not exchange huge data (>1Mb) between services and application 不要在服务和应用程序之间交换大量数据(> 1Mb)
1Mb According http://developer.android.com/reference/android/os/TransactionTooLargeException.html 1Mb根据http://developer.android.com/reference/android/os/TransactionTooLargeException.html
Do you override 你覆盖了吗?
onSaveInstanceState()
if you do check what you are saving there could also be an error. 如果你确实检查了你要保存的内容,那么也可能会出现错误。 Like if you do 就像你这样做
outState.putParcelable("key", outState); //Error is passing the bundle
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.