Is there any limit of bundle in Android?

It depends on the purpose of the bundle. The bundle itself is only limited by the amount of memory.

The two main uses for bundles are to pass information between components using intents and to save the state of activities.

1. Intents / Binders

When used to pass information between Android components the bundle is serialized into a binder transaction. The total size for all binder transactions in a process is 1MB. If you exceed this limit you will receive this fatal error “!!! FAILED BINDER TRANSACTION !!!”

It’s recommend that you keep the data in these bundles as small as possible because it’s a shared buffer, anything more than a few kilobytes should be written to disk.

Reference: https://android.googlesource.com/platform/frameworks/base/+/jb-release/core/jni/android_util_Binder.cpp

ALOGE("!!! FAILED BINDER TRANSACTION !!!");
        // TransactionTooLargeException is a checked exception, only throw from certain methods.
        // FIXME: Transaction too large is the most common reason for FAILED_TRANSACTION
        //        but it is not the only one.  The Binder driver can return BR_FAILED_REPLY
        //        for other reasons also, such as if the transaction is malformed or
        //        refers to an FD that has been closed.  We should change the driver
        //        to enable us to distinguish these cases in the future.

Reference: http://developer.android.com/reference/android/os/TransactionTooLargeException.html

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.

2. Saved Instance State ( Activity onSaveInstanceState, onPause etc. )

I found no limit in the size I could store in the bundle used to preserve Activity state. I did some tests and could successfully store about 175mb before I received an out of memory exception trying to allocate the data I was attempting to save.

Update: This research was performed in 2014, newer versions of Android may crash with bundles over 500kb

Leave a Comment