【问题标题】:Caused by android too large exception (data parcel 2076400 bytes)android too large引发的异常(数据包2076400字节)
【发布时间】:2020-02-19 08:01:12
【问题描述】:

尝试使用 Intent Extras 将哈希映射数据传递给另一个活动会导致事务过大异常错误。(数据包 2076400 字节)

这是将地图数据传递给另一个收到错误的活动的代码。

if {

    mCountDownTimer =   new CountDownTimer(2000, 1000) {
    public void onTick(long millisUntilFinished) {}

    public void onFinish() {
        Intent intent = new Intent(Main2Activity.this, 
        ShowImagesActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
        Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("hashMap", map);
        startActivity(intent);
        if(Splash.Getproduct ==null) {
            if (mInterstitialAd.isLoaded()) 
             mInterstitialAd.show();
       }.start();
    }
}

如何避免这种情况并将此数据发送到另一个活动。

【问题讨论】:

  • Intent 中的数据大小有限制。看起来你已经达到了。不要将 Intent 用于大数据。

标签: android exception large-data


【解决方案1】:

您可以通过意图发送的数据量是有限制的。 它是 1 MB。理想情况下,您应该只通过意图发送几 KB 的数据。

您的数据大小约为 2 MB,超出了此限制。 如果您打算传递这么多数据,您也可以将其保存在数据库或内存数据存储中。

Binder 事务缓冲区有一个有限的固定大小,目前为 1MB,由该进程正在进行的所有事务共享。由于此限制是在进程级别而不是在每个活动级别,因此这些事务包括应用程序中的所有绑定事务,例如 onSaveInstanceState、startActivity 以及与系统的任何交互。当超出大小限制时,会抛出 TransactionTooLargeException。

https://developer.android.com/guide/components/activities/parcelables-and-bundles

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 2015-04-17
    • 1970-01-01
    • 2019-10-22
    • 2021-06-19
    • 1970-01-01
    相关资源
    最近更新 更多