Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 223
Milo Avatar asked Feb 14 '14 20:02

Milo


3 Answers

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.

like image 125
Nemanja Kovacevic Avatar answered Nov 17 '22 04:11

Nemanja Kovacevic


according What to do on TransactionTooLargeException :

This can occur, when you pass lot of data through 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.

Do not exchange huge data (>1Mb) between services and application

1Mb According http://developer.android.com/reference/android/os/TransactionTooLargeException.html

like image 22
Saeid Avatar answered Nov 17 '22 05:11

Saeid


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
like image 38
Santa Teclado Avatar answered Nov 17 '22 05:11

Santa Teclado