仅在牛轧糖上的TransactionTooLargeException [英] TransactionTooLargeException only on Nougat

查看:147
本文介绍了仅在牛轧糖上的TransactionTooLargeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行的应用程序在Android版本低于Nougat的设备上运行良好。

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

当我在装有Nougat的设备上启动该应用程序时,按首页按钮,应用程序崩溃并且在logcat中,我有:

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.

推荐答案

我也有同样的问题。谷歌论坛上的许多开发人员都抱怨过这一点。他们的答案是WAI(按预期工作),因为他们不建议在该州保存太多数据。
因此建议只向Intent添加非常基本的参数。
如果要在活动或片段之间发送数据,

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,


  • 将数据存储在(临时)文件中并在文件URI。
    如果要将
    大量数据传输到完全不同的应用程序,则此选项可能是您唯一的选择。将数据
    存储在Application实例中;

  • 创建一个包含您传递的
    数据的单例容器。

  • 如果使用的是FragmentStatePageAdapter,请添加以下代码避免保存状态数据。

  • 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;
}


参考:

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

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

这篇关于仅在牛轧糖上的TransactionTooLargeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆