TransactionTooLargeException in Nougat

后端 未结 4 992
故里飘歌
故里飘歌 2021-01-06 00:57

Exception

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


        
相关标签:
4条回答
  • 2021-01-06 01:30

    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.

    public String getImage() {
        return image;
    }
    
    public void setImage(String image) {
        this.image = image;
    }
    
    0 讨论(0)
  • 2021-01-06 01:32

    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 RuntimeException if 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 Activity
    MyActivity activity = (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.

    0 讨论(0)
  • 2021-01-06 01:40

    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.

    0 讨论(0)
  • 2021-01-06 01:45

    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.
    0 讨论(0)
提交回复
热议问题