简体   繁体   English

使用巨型recycleview时出现android.os.TransactionTooLargeException

[英]android.os.TransactionTooLargeException when using giant recycleview

I'm getting this annoying exception in my main activity sometimes.有时我的主要活动中会遇到这个烦人的异常。
the stack trace is like this:堆栈跟踪是这样的:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.tomatedigital.lottogram, PID: 4430
    java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 543588 bytes
        at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4156)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6944)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: android.os.TransactionTooLargeException: data parcel size 543588 bytes
        at android.os.BinderProxy.transactNative(Native Method)
        at android.os.BinderProxy.transact(Binder.java:761)
        at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:5147)
        at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4148)
        at android.os.Handler.handleCallback(Handler.java:789) 
        at android.os.Handler.dispatchMessage(Handler.java:98) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6944) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 

The trace itself is not very helpfull since it doesn't specify which component or what transaction Id or Tag is related to the Exception (google please think about the debuggability of the crap you put out there)... but i do suspect it is the recycleview i have in my main activity.跟踪本身并不是很有帮助,因为它没有指定哪个组件或哪个事务 ID 或标签与异常相关(谷歌请考虑你放在那里的废话的可调试性)......但我确实怀疑它是我在主要活动中的recycleview。

This recycleview might get super loaded, THOUSANDS of items.这个recycleview 可能会超载,成千上万的项目。 each of them contains: 3 small strings, 1 large string and one small bitmap.每个包含:3 个小字符串、1 个大字符串和一个小字符串 bitmap。

When this recyclerview is overloaded and the activity is suspended this exception is thrown.当这个 recyclerview 被重载并且活动被挂起时,这个异常被抛出。 Since the recyclerview is created inflating the layout.xml, android do save its state automaticly.由于创建了 recyclerview 膨胀布局。xml,android 确实保存它的 state 自动。

Is there any easy way to workaround this problem?有什么简单的方法可以解决这个问题吗?
Is possible to set the App to allow "super large Transaction"?是否可以将App设置为允许“超大交易”?
What can i do?我能做些什么?

================UPDATE=================== to provide aditional information about my Activity ================更新=================== 提供有关我的活动的其他信息

 @Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        outState.putSerializable("media", this.media); //this is a domain class
        outState.putBoolean("canceled", this.canceled);
        outState.putInt("speed", this.speed);
        outState.putLong("startTime", this.startTime);
        outState.putSerializable("comments", (Serializable) this.adapter.getList()); //this is the large data
        outState.putBoolean("commentLoadComplet", this.complete);
        outState.putSerializable("fetched", (Serializable) this.fetched);
        outState.putSerializable("igiboAttendees", (Serializable) this.igiboAttendees);
        outState.putLong("winnerId", this.winnerId);

        super.onSaveInstanceState(outState);
    }

This is typically caused by saving large amounts of data in onSaveInstanceState, not only for the activity in which the exception occurred, but also in other activities currently in the back stack.这通常是由于在 onSaveInstanceState 中保存了大量数据造成的,不仅针对发生异常的活动,还包括当前在后台堆栈中的其他活动。

One solution is to use the ViewModel class to maintain state instead of onSaveInstanceState:一种解决方案是使用 ViewModel class 来维护 state 而不是 onSaveInstanceState:

ViewModel Overview ViewModel 概述

You may still use onSaveInstanceState for small amounts of data, but keep in mind it adds up over all the activities.对于少量数据,您仍然可以使用 onSaveInstanceState,但请记住,它会累加所有活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 执行queryIntentActivities时android.os.TransactionTooLargeException - android.os.TransactionTooLargeException when executing queryIntentActivities 启动器中的android.os.transactiontoolargeexception - android.os.transactiontoolargeexception in Launcher android.os.TransactionTooLargeException的牛轧糖 - android.os.TransactionTooLargeException on Nougat 上载到Firebase时获取android.os.TransactionTooLargeException - Getting android.os.TransactionTooLargeException When uploading to Firebase 与其他应用共享图片时获取android.os.TransactionTooLargeException - Getting android.os.TransactionTooLargeException when sharing picture with others app Android中的android.os.TransactionTooLargeException错误 - android.os.TransactionTooLargeException error in Android 如何避免得到“android.os.TransactionTooLargeException” - how to avoid getting the “android.os.TransactionTooLargeException” 随机抛出android.os.TransactionTooLargeException - android.os.TransactionTooLargeException thrown randomly AppWidgetManager.updateAppWidget中的android.os.TransactionTooLargeException - android.os.TransactionTooLargeException in AppWidgetManager.updateAppWidget 反应原生 - android.os.TransactionTooLargeException - React Native - android.os.TransactionTooLargeException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM