Creating intent with a large amount of data in extras
public static Intent createIntent(Context context, List<PhotoItem> gallery, int indexOf) {
Intent intent = new Intent(context, GalleryViewActivity.class);
intent.putExtra(EXTRA_PHOTO_INDEX, indexOf);
intent.putExtra(EXTRA_PHOTO_OBJECT, new Gson().toJson(gallery));
return intent;
}
Then running the activity:
startActivity(createIntent(...
crashes application with error:
Exception when starting activity android.os.TransactionTooLargeException: data parcel size...
How to avoid such errors when data is too large in the list?
You are passing whole
List<PhotoItem>
to yourGalleryViewActivity
withIntent
. So it might possible that your list ofList<PhotoItem>
can have many data. So sometime system can not handle much data to transfer at a time.Please avoid to pass large amount of data with Intent.
You can use
SharedPreferences
to store your array list and retrieve the same on other activity.You will have your list in listGallery variable. You can retrieve your index as the same way you are using right now.