Skip to content Skip to sidebar Skip to footer

Why Does Android N Throw Transactiontoolargeexception When Using Bundles?

On Android N whenever I pass some binary or large data in bundle I get a TransactionTooLargeException, however it runs without issues on android M and below. How can I solve this?

Solution 1:

There has been a behavior change in Android N

Quoting the docs:

Many platform APIs have now started checking for large payloads being sent across Binder transactions, and the system now rethrows TransactionTooLargeExceptions as RuntimeExceptions, instead of silently logging or suppressing them. One common example is storing too much data in Activity.onSaveInstanceState(), which causes ActivityThread.StopInfo to throw a RuntimeException when your app targets Android 7.0.

Note: Apps targeting M or below won't throw the exception, they will just silently log or suppress them

How to solve this:

Rethink why you need so much data in bundle in the first place.

  1. If it is binary data or a bitmap, it is best to store it in a file and pass the path in the bundle.

  2. If you are passing too many objects

    • You can use libraries like Otto,EventBus to avoid it.

    • Just pass the necessary info required for constructing the Object once again.

    • Create a singleton class and set the data there and access it in another Activity or Fragment from there.

Post a Comment for "Why Does Android N Throw Transactiontoolargeexception When Using Bundles?"