java – Is there a size limit for putParcelableArrayListExtra?-ThrowExceptions

Exception or error:

I’m using putParcelableArrayListExtra to send an ArrayList which contains all songs on the device to another Activity.

Now i was wondering if there is any size limit for sending data through intents with putParcelableArrayListExtra.

Ex. What if someone has more than 10k songs on his device, would this cause any problems when sending an arraylist which contains alot of songs to another Activity?

My code

@Override
   public void onClickItem(int position) {
        if (getActivity() != null) {
            myList = Main.getInstance().songs;
            Intent intent = new Intent(getActivity(), ListSongsActivity.class);
            intent.putParcelableArrayListExtra("myList ", myList);
            startActivity(intent);
        }
}
How to solve:

There is the size limit for the bundle while performing the Activity transaction. In case the limit is exceeded the TransactionTooLargeException is thrown.

The Binder transaction buffer has a limited fixed size, currently 1Mb,
which is shared by all transactions in progress for the process.
Consequently, this exception can be thrown when there are many
transactions in progress even when most of the individual transactions
are of moderate size.

Reference: https://developer.android.com/reference/android/os/TransactionTooLargeException

Leave a Reply

Your email address will not be published. Required fields are marked *