Skip to content Skip to sidebar Skip to footer

Exception When Starting Activity Android.os.transactiontoolargeexception: Data Parcel Size

Creating intent with a large amount of data in extras public static Intent createIntent(Context context, List gallery, int indexOf) { Intent intent = new

Solution 1:

You are passing whole List<PhotoItem> to your GalleryViewActivity with Intent. So it might possible that your list of List<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.

Initialize your SharedPreferences using:

SharedPreferencesprefrence=  PreferenceManager.getDefaultSharedPreferences(context);
Editoreditor= prefrence.edit();

You can use this way to store list in Preference variable

publicstatic Intent createIntent(Context context, List<PhotoItem> gallery, int indexOf){
    Intent intent = newIntent(context, GalleryViewActivity.class);
    intent.putExtra(EXTRA_PHOTO_INDEX, indexOf);

    editor.putString("GallaryData", newGson().toJson(gallery));
    editor.commit();

    return intent;
}

Now in your GalleryViewActivity.java file

SharedPreferencesprefrence=  PreferenceManager.getDefaultSharedPreferences(context);
Editoreditor= prefrence.edit();

StringgalleryData= prefrence.getString("GallaryData", "");
List<PhotoItem> listGallery = newGson().fromJson(galleryData, newTypeToken<List<PhotoItem>>() {}.getType());

You will have your list in listGallery variable. You can retrieve your index as the same way you are using right now.

Post a Comment for "Exception When Starting Activity Android.os.transactiontoolargeexception: Data Parcel Size"