android.os.TransactionTooLargeException thrown randomly

Milo picture Milo · Feb 14, 2014 · Viewed 9k times · Source

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. 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. 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.

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?

Thanks

Answer

Nemanja Kovacevic picture Nemanja Kovacevic · Mar 25, 2015

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. 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. To be fair it's better than using Parcelable via Parceler lib, I've never used pure Parcelable. For more details see my blog post on this topic.