安卓intent跳转界面传递大数据处理

博客介绍了如何处理在安卓中使用Intent传递大数据时遇到的android.os.TransactionTooLargeException异常。通过创建自定义数据类并调整启动及接收页面的代码来解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android.os.TransactionTooLargeException: data parcel size 562012 bytes传递大数据异常

针对安卓intent传递大数据问题,我也是最近才遇到,网上找了各种方法,如今分享一下:
首先 新建一个数据类:

import android.os.Binder;

/**
 * 应对跳转考试答题页 intent传递大数据时候
 */
public class BigBinder extends Binder {

    public AnswerPageEntity answerPageEntity;

    public BigBinder(AnswerPageEntity answerPageEntity) {

        this.answerPageEntity=answerPageEntity;

    }

}

其中是我要传递的对象类;

然后调整开始页代码如下:

 Intent intent = new Intent(this, NewAnswerPageActivity.class);
        Bundle bundle=new Bundle();
        BigBinder bigBinder=new BigBinder(answerPageEntity);
        bundle.putBinder("bigData",bigBinder);
        intent.putExtra("bundle",bundle);
        startActivity(intent);

接收的界面代码如下:

 Bundle bundle=intent.getBundleExtra("bundle");
            BigBinder bigBinder = (BigBinder) bundle.getBinder("bigData");
            Log.d("mawl","获取的intent数据是=="+bigBinder.answerPageEntity.getCode());
            mAnswerPageEntity = bigBinder.answerPageEntity;

ok 完成了,大家可以试试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值