Android - TransactionTooLargeException

Mys*_*elf 5 android exception

在 ProcessRecord{3c67ecf8080:com.example/u0a171} android.os.TransactionTooLargeException 中引发启动活动异常:数据包大小 572488 字节

传递数据

Intent intent = new Intent(activity, SearchListActivity.class);
intent.putExtra(HRConstants.SEARCHLIST, searchResponse);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

获取数据

Intent intent = getIntent();
searchResponse = intent.getParcelableExtra(HRConstants.SEARCHLIST);
searchLists = searchResponse.getSearchResults();
Run Code Online (Sandbox Code Playgroud)

minSdkVersion15 岁,targetSdkVersion26 岁。

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

Red*_*eda 5

这是因为 Android 中的 Intent 只能携带不超过 1MB 的数据。解决方法是将“searchResult”放入公共静态对象中

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

在 SearchListActivity 中,而不是做

getIntent.getExtras();
Run Code Online (Sandbox Code Playgroud)

您可以访问现在保存到的对象

List<Search> list = YourActivity.SeachResponse;
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助