- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我将 Nexus 5X 更新为 Android N,现在当我在其上安装应用程序(调试或发布)时,我在每个具有 Bundle in extras 的屏幕转换时都会收到 TransactionTooLargeException。该应用程序可在所有其他设备上运行。 PlayStore 上的旧应用程序具有大部分相同的代码,正在 Nexus 5X 上运行。有人遇到同样的问题吗?
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 592196 bytes
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3752)
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:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.os.TransactionTooLargeException: data parcel size 592196 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:615)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3606)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3744)
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:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
最佳答案
当你看到 TransactionTooLargeException
在 Activity
正在停止的过程中发生时,这意味着 Activity
正试图发送它保存的向系统操作系统说明 Bundles
以便安全保存以便稍后恢复(在配置更改或进程死亡之后),但它发送的一个或多个 Bundles
太大。一次发生的所有此类事务的最大限制约为 1MB,即使没有单个 Bundle
超过该限制,也可以达到该限制。
这里的罪魁祸首通常是在 Activity
或 Activity 托管的任何
。这通常发生在保存特别大的东西(如 Fragments
的 onSaveInstanceState
内保存了太多数据Bitmap
时),但也可能发生在发送大量较小数据时,如 Parcelable
对象列表。 Android 团队多次明确表示,onSavedInstanceState
中只应保存少量与 View 相关的数据。但是,开发人员通常会保存网络数据页面,以使配置更改看起来尽可能平滑,而不必再次重新获取相同的数据。从 2017 年 Google I/O 开始,Android 团队已经明确表示,Android 应用的首选架构可以节省网络数据
他们新的 ViewModel
框架和 Room
持久性库旨在帮助开发人员适应这种模式。如果您的问题是在 onSaveInstanceState
中保存了太多数据,那么使用这些工具更新到这样的架构应该可以解决您的问题。
就个人而言,在更新到该新模式之前,我想使用我现有的应用程序,同时绕过 TransactionTooLargeException
。为此,我编写了一个快速库:https://github.com/livefront/bridge .它使用相同的一般思想,即在配置更改后从内存中恢复状态以及在进程死亡后从磁盘中恢复状态,而不是通过 onSaveInstanceState
将所有状态发送到操作系统,但只需对现有代码进行极少的更改即可利用。不过,任何符合这两个目标的策略都应该可以帮助您避免异常,同时又不会牺牲您保存状态的能力。
最后一点:您在 Nougat+ 上看到此内容的唯一原因是,最初如果超出绑定(bind)器事务限制,将保存状态发送到操作系统的过程将静默失败,Logcat 中仅显示此错误:
!!! Binder 交易失败!!!
在 Nougat 中,无声故障升级为硬崩溃。值得称赞的是,这是开发团队在 the release notes for Nougat 中记录的内容。 :
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.
关于牛轧糖上的 android.os.TransactionTooLargeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39098590/
我是一名优秀的程序员,十分优秀!