Java 如何在android中通过intent发送大型json数据
我已经知道如何使用Intent在活动之间发送数据,问题是,我的服务器请求返回字符串base64中图像的Java 如何在android中通过intent发送大型json数据,java,android,Java,Android,我已经知道如何使用Intent在活动之间发送数据,问题是,我的服务器请求返回字符串base64中图像的ArrayList,我注意到一个大字符串使应用程序崩溃,还有其他方法吗?我通常是这样做的: 1活动: String passing_data = new Gson().toJson(user); Intent intent = new Intent(activity,UserAdsView.class); intent.putExtra("passed_data",passing_data);
ArrayList
,我注意到一个大字符串使应用程序崩溃,还有其他方法吗?我通常是这样做的:
1活动:
String passing_data = new Gson().toJson(user);
Intent intent = new Intent(activity,UserAdsView.class);
intent.putExtra("passed_data",passing_data);
activity.startActivity(intent);
String target = getIntent().getStringExtra("passed_data");
UserModelView userModelView = new Gson().fromJson(target,UserModelView.class);
2活动:
String passing_data = new Gson().toJson(user);
Intent intent = new Intent(activity,UserAdsView.class);
intent.putExtra("passed_data",passing_data);
activity.startActivity(intent);
String target = getIntent().getStringExtra("passed_data");
UserModelView userModelView = new Gson().fromJson(target,UserModelView.class);
它在控制台或其他地方没有显示任何错误,只是崩溃并重新打开以前的活动。谢谢 嗯,你什么意思?您是要传递JSON对象还是要传递arraylist 我猜您需要一个包和一个序列化程序。试试这样的
// 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);
那么在你的新活动中,你需要这样的东西:
ArrayList<String> target = (ArrayList<String>) b.getSerializable("passed_data");
ArrayList target=(ArrayList)b.getSerializable(“传递的_数据”);
Hmmm.你是什么意思?您是要传递JSON对象还是要传递arraylist
我猜您需要一个包和一个序列化程序。试试这样的
// 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);
那么在你的新活动中,你需要这样的东西:
ArrayList<String> target = (ArrayList<String>) b.getSerializable("passed_data");
ArrayList target=(ArrayList)b.getSerializable(“传递的_数据”);
将图像保存到文件系统并将文件名传递到intent?在我的情况下,这是一个“临时”图像,在第一个活动中,它显示一个包含少量信息的CardView和一个图像,当我单击该项目时,使用这些附加信息启动一个新活动,包括“stringsImagesArray”,但我无法想象!您可以在第二个活动中再次请求服务器,而不是传递第一个活动中的值。即使它是临时的,您也可以将其保存在磁盘上,在不再需要它后将其删除将映像保存到文件系统并传递文件名?在我的情况下,这是一个“临时”映像,在第一个活动中,它显示了一个带有一些信息和图像的CardView,当我单击该项目时,会使用这些附加信息(包括“stringsImagesArray”)启动一个新活动,但我无法让它思考!您可以在第二个活动中再次请求服务器,而不是传递第一个活动的值。即使是临时的,您也可以将其保存在磁盘上,并在不再需要后将其删除。数组列表是一个属性。未分隔数组列表是一个属性。未分隔数组列表是一个属性