2

I am getting TransactionTooLargeException in an activity only when a particular fragment is added in it. The exception happens only when the app is sent to background and brought back or when the phone is locked and unlocked.

I had logged the app and found that although onPause() is being invoked when app goes to background, onResume(), onStart(), onRestoreInstanceState() etc is not invoked when app is brought to foreground.

The app doesn't throw the exception when the fragment is added in normal flow only if app goes to background the exception is thrown and the app is closed. Any idea what could be the root cause here?

pvn
  • 2,016
  • 19
  • 33

1 Answers1

0

I encountered this problem sometime ago. The problem was I was saving a parcelable/ serialisable object inside an activity's fragment onSaveInstanceState(Bundle bundle). This activity was in activity stack i.e. it was not the current activity. Inside onResume of current fragment I was exchanging additional serialisable data using intent bundle.

Try to limit this serialisable data save / exchange so that it remains within limits otherwise TransactionTooLargeException error will be thrown.

The Binder transaction buffer has a limited fixed size, currently 1Mb

The key to avoiding TransactionTooLargeException is to keep all transactions relatively small. Try to minimize the amount of memory needed to create a Parcel for the arguments and the return value of the remote procedure call. Avoid transferring huge arrays of strings or large bitmaps. If possible, try to break up big requests into smaller pieces.

random
  • 10,238
  • 8
  • 57
  • 101
  • I am not saving anything in onSaveInstanceState(). I infact over wrote onSaveInstanceState() to store null – pvn Aug 17 '16 at 06:46
  • Can you check your logs carefully and see if you have `!!! FAILED BINDER TRANSACTION !!! (parcel size =` ) logged anywhere? – random Aug 17 '16 at 06:51
  • ya that is shown up. What I didn't understand though if its the bundle that stores state which causes the problem, in that case making the bundle store null explicitly onSaveInstanceState() should have stored the problem(although I wasnt storing a bundle in onSaveInstanceState). Also if thats not the cause onResume() and onRestoreInstanceState() should have been called before the exception is thrown – pvn Aug 17 '16 at 08:01
  • In my case, it was related to the backStackEntry of the navigation component. I left an answer here: https://stackoverflow.com/a/73008611/2860701 – Alberto Jul 17 '22 at 01:09