Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - TransactionTooLargeException

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

Passing data

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

Getting Data

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

My minSdkVersion is 15 and targetSdkVersion is 26.

The response contained 1736 items followed by an exception. It works fine with fewer items.

like image 725
Myself Avatar asked Dec 22 '17 04:12

Myself


1 Answers

This is because intents in Android can carry no more than 1MB of data. A workaround would be puting "searchResult" inside a public static object

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

In the SearchListActivity, instead of doing

getIntent.getExtras();

you can access your object now saved into

List<Search> list = YourActivity.SeachResponse;

Hope this helps

like image 63
Reda Avatar answered Nov 01 '22 12:11

Reda