安卓 - TransactionTooLargeException

标签 android exception

Exception thrown launching activities in ProcessRecord{3c67ecf8080:com.example/u0a171} android.os.TransactionTooLargeException: data parcel size 572488 bytes

传递数据

Intent intent = new Intent(activity, SearchListActivity.class);
intent.putExtra(HRConstants.SEARCHLIST, searchResponse);
startActivity(intent);

获取数据

Intent intent = getIntent();
searchResponse = intent.getParcelableExtra(HRConstants.SEARCHLIST);
searchLists = searchResponse.getSearchResults();

我的minSdkVersion是15,targetSdkVersion是26。

响应包含 1736 个项目,后跟异常。它适用于更少的项目。

最佳答案

这是因为 Android 中的 Intent 最多只能携带 1MB 的数据。解决方法是将“searchResult”放在公共(public)静态对象中

Intent intent=new Intent(activity,SearchListActivity.class);
//intent.putExtra(HRConstants.SEARCHLIST,  searchResponse);
YourActivity.SearchResponse = searchResponse;
startActivity(intent);

在 SearchListActivity 中,而不是做

getIntent.getExtras();

你可以访问你现在保存的对象

List<Search> list = YourActivity.SeachResponse;

希望对你有帮助

关于安卓 - TransactionTooLargeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47935701/

相关文章:

c++ - 谁来管理参数中复制构造函数抛出的异常?

c++ - 如何减少非异常异常的调试开销

c# - VS : XAML-Designer Error (ArgumentException - Same Key has already been added)

java - GreenRobot异常: de. greenrobot.event.EventBusException:调用订阅者失败

java - 以编程方式添加时如何为 GridLayout 子项设置 layout_columnWeight?

Android - 使用 db.enableWriteAheadLogging 方法获取 java.lang.NoSuchMethodError

android - Google Chrome for Android 远程网络调试

java.io.FileNotFoundException :/storage/emulated/0/downloadedfilem. jpg(权限被拒绝)

Android ffmpeg0.8 不能用 android ndk5 和 cygwin 编译器编译

java - 在游戏之间出现 IndexOutOfBoundsException