0

I sometimes get TransactionTooLargeException in onSaveInstanceState. So, I'm assuming that the size of my Bundle being too large is causing this. I'd like to log its exact/approx size so I can get a rough estimate of the amount I need to minimize it by.

Right now, the only way I can find its size is when the TransactionTooLargeException is thrown with

E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 1026104)
D/AndroidRuntime: Shutting down VM
I/art: Compiler allocated 6MB to compile void com.example.ExampleModel.writeToParcel(android.os.Parcel, int)
E/UncaughtException: java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1026104 bytes
Veneet Reddy
  • 2,707
  • 1
  • 24
  • 40
  • I think you're attacking the problem from the wrong direction. Why do you have so much data to save? Bundle sizes should rarely go over a few K. Most likely you're storing things that should go in files (like images) or databases (like large parsed network responses). – Gabe Sechan Jan 24 '17 at 18:01
  • I totally agree with you. I was just curious if there was a way to log its size. – Veneet Reddy Jan 24 '17 at 18:10
  • You could write it to a Parcel then marshall the Parcel, which will return a byte[] of the contents. The take the size of that. – Gabe Sechan Jan 24 '17 at 18:41
  • You aren't using a `FragmentStatePagerAdapter` by any chance, are you? https://android.jlelse.eu/rip-transactiontoolargeexception-7256cf14cd69 – Tim Kist Jan 22 '18 at 14:44
  • Maybe too late, but You can try this https://github.com/guardian/toolargetool – Roman Soviak May 08 '18 at 16:44
  • That looks exactly like what I was looking for. You can post it as an answer and I'll accept. – Veneet Reddy May 08 '18 at 18:28

1 Answers1

0

please click here for reference

To take advantage of Dex In Process, you’ll need to modify your gradle.properties file and increase the amount of memory allocated to the Gradle Daemon VM by 1 Gb, to a minimum of 2 Gb, using the org.gradle.jvmargs property:

org.gradle.jvmargs=-Xmx2048m