Skip to content Skip to sidebar Skip to footer

Transactiontoolargeexception In Nougat

Exception 05-12 15:42:45.791 11043-11043/ E/UncaughtException: java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 631792 bytes

Solution 1:

Your are passing too much data to your Fragment in setArguments(). Your Fragment will work, but when it tries to save its instance state it overflows the transaction buffer. This throws a RuntimeExceptionif you target Android 7.0 (API 24 or higher). To preserve backwards compatibility and not break existing apps, the new behaviour is only used if you target API 24 or higher. If you target API < 24, the transaction buffer overflow exception is caught and silently ignored. This means that your data will not be persistently saved, which you may (or may not) notice.

Your code is broken. You should not pass large amounts of data to the Fragment in setArguments(). You can keep your data in your Activity. When the Fragment wants to access the data, it can always so something like this:

// Get the owning ActivityMyActivityactivity= (MyActivity)getActivity();
// Get the data from the Activity
List<Data> data = activity.getData();

In your Activity, write a getData() method that returns a reference to whatever data the Fragment needs.

In this way, the data is held in the Activity and the Fragment can get access to it whenever it needs to.

Solution 2:

Android 7.0 (Nogat) includes a variety of system and API behaviour changes. Regarding TransactionTooLarge Exception :

In Android 7.0, 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.

Possible Solutions : 1. Save required object in global cache and pass only the key to DetailsActivity to retrieve the object.

Solution 3:

Regarding the Doc This Exception throw when value are too large to fit in the transaction buffer. And might be a complicated issue, for a big project, where you can invokes several actions with sending Intent in difference places.

Your example demonstrate this issue, even with single object. And you should change your transferring behavior at all. For ex. by trimming object, to contain only important info. Intent Extra Data should have only lightweight info!


In you example you have field, which might produce this issue. Probably you are using Base64 Encoded image. Exception with message text, specific only for Android 23. Check the doc.

publicStringgetImage() {
    return image;
}

publicvoidsetImage(String image) {
    this.image = image;
}

Solution 4:

Read this article http://nemanjakovacevic.net/blog/english/2015/03/24/yet-another-post-on-serializable-vs-parcelable/ should help you.

My solution:

  1. Save your objects in some storage (SharedPreferences, raw JSON, SQLLite or Realm database etc.)

  2. Put to your bundle only object 'id' (simple type: int long etc.)

  3. Get 'id' from intent and find it in your storage, then retrieve the object.

Post a Comment for "Transactiontoolargeexception In Nougat"