TransactionTooLargeException only on Nougat

Marcin Bortel picture Marcin Bortel · Apr 18, 2017 · Viewed 9.1k times · Source

I've go an app that works well on devices with Android versions lower than Nougat.

When I launch the app on a device with Nougat and I press home button, the app crashes and in logcat I have:

!!! FAILED BINDER TRANSACTION !!!  (parcel size = 1819712)
Unhandled exception
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1819712 bytes
    at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3781)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
 Caused by: android.os.TransactionTooLargeException: data parcel size 1819712 bytes
    at android.os.BinderProxy.transactNative(Native Method)
    at android.os.BinderProxy.transact(Binder.java:615)
    at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3636)
    at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3773)
    at android.os.Handler.handleCallback(Handler.java:751) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6119) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

Is there a simple solution? This problem appears only on Nougat.

Answer

flame3 picture flame3 · Jul 4, 2017

I have the same problem. This has been complained by many developers on the google forum. Their answer is WAI (work as intended) because they don't recommend to save too much data in the state. So the advice is to only add very basic arguments to an Intent. If you want to send data among activities or fragments,

  • Store the data in a (temporary) file and pass around the file URI. This option is probably your only option if you want to transfer large amounts of data to a completely different app. Store the data in the Application instance;
  • Create a singleton container holding the data you pass around.
  • If you are using FragmentStatePageAdapter, add the following code to avoid it saving state data.

    @Override    
    public Parcelable saveState() {
            Bundle bundle = (Bundle) super.saveState();
            bundle.putParcelableArray("states", null); // Never maintain any states from the base class to avoid TransactionTooLargeException
            return bundle;
    }
    

Reference:

https://issuetracker.google.com/issues/37103380

https://www.neotechsoftware.com/blog/android-intent-size-limit