gpt4 book ai didi

java - android中如何通过intent发送大的json数据

转载 作者:太空宇宙 更新时间:2023-11-04 11:49:42 25 4
gpt4 key购买 nike

我已经知道如何使用 Intent 在 Activity 之间发送数据,问题是,我的服务器请求返回字符串 base64 中的图像的 ArrayList,并且我注意到大字符串使应用程序崩溃,还有其他方法可以做到这一点吗?我通常这样做:

1 项 Activity :

String passing_data = new Gson().toJson(user);
Intent intent = new Intent(activity,UserAdsView.class);
intent.putExtra("passed_data",passing_data);
activity.startActivity(intent);

2 Activity :

String target = getIntent().getStringExtra("passed_data");
UserModelView userModelView = new Gson().fromJson(target,UserModelView.class);

它不会在控制台中显示任何错误或其他内容,它只是崩溃,然后重新打开之前的 Activity 。谢谢!

最佳答案

嗯。你是什​​么意思?您是否尝试传递 JSON 对象还是尝试传递数组列表?

我猜您需要一个 bundle 和一个序列化器。尝试这样的事情。

    // Create your new Intent
Intent intent = new Intent(activity,UserAdsView.class);
//create a bundle
Bundle b = new Bundle();
//when you add a list of objects (JSON or Otherwise), use a serializer
b.putSerializable("passed_data", passing_data);

intent.putExtras(b);
startActivity(intent);

然后在你的新 Activity 中你需要这样的东西:

    ArrayList<String> target = (ArrayList<String>) b.getSerializable("passed_data");

关于java - android中如何通过intent发送大的json数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41970696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com