I want to know whether android bundle's data size has upper limit. I try to post data by bundle which size >80k,and throw android fatal exception.The data is Serializable.
-
I guess it depends on android version, in android 9 or lower we were facing `tooLargeDataException` in our devices but not in new devices having higher android version. – pintu236 Sep 20 '22 at 06:53
7 Answers
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.
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

- 6,771
- 4
- 38
- 43
-
1I'm interested in the test you did on "saved instance state". I got the "FAILED BINDER TRANSACTION" error in Logcat when I put a huge string into a bundle inside onSaveInstateState(). It seems the data is saved and restored properly. The only issue is that I got the above error in the log which bothers me if this will ever fail on certain devices/api versions. When you successfully stored 175mb did you get the error at all? – yongsunCN Feb 25 '16 at 19:23
-
32 is not true on 7.0+. See https://developer.android.com/about/versions/nougat/android-7.0-changes.html near the bottom. – Reuben Tanner Apr 10 '17 at 17:23
-
3@yongsunCN the 175MB statement is wrong. On Android 7.0+ (Nougat), an exception is thrown when the size of the bundle exceeds a limit, which is nowwhere near 175MB, but something like 0.5MB. Previous versions logged a warning only, but from that version an exception is thrown. – Minas Mina Nov 27 '17 at 18:52
I think the limit is 500kb. You can save the passed object in a file and send the path of the file in the bundle instead. You can check similar question asked by me at SO
-
1
-
Check the [discussion here](https://groups.google.com/forum/#!topic/android-developers/KKEyW6XdDvg/discussion) – Tarun Dec 18 '11 at 16:51
-
1In that discussion you see several numbers (500kb and 1mb), of which the latter by someone who identifys herself as "Dianne Hackborn Android framework engineer", so if you want a number from that thread, I would pick that one? Further more, I'm not really sure that the subject there is "bundle data" – Nanne Dec 18 '11 at 18:22
-
-
The limit is somewhere between a little less than 512KB and little less than 1MB since it's device specific. See this blog post for more info http://nemanjakovacevic.net/blog/english/2015/03/24/yet-another-post-on-serializable-vs-parcelable/ – Nemanja Kovacevic Mar 25 '15 at 01:47
-
1Bundle itself neither can limit data it holds nor even knows how much does it hold. Binder transaction limits data size. – Miha_x64 Aug 24 '18 at 08:33
The Binder transaction buffer has a limited fixed size, currently 1MB, which is shared by all transactions in progress for the process. Since this limit is at the process level rather than at the per activity level, these transactions include all binder transactions in the app such as onSaveInstanceState, startActivity and any interaction with the system. When the size limit is exceeded, a TransactionTooLargeException is thrown.
For the specific case of savedInstanceState, the amount of data should be kept small because the system process needs to hold on to the provided data for as long as the user can ever navigate back to that activity (even if the activity's process is killed). We recommend that you keep saved state to less than 50k of data.

- 447
- 5
- 8
Yes it has, and now in android Nougat it will crash if you exceeded the limit roughly(500Kb).

- 1,901
- 17
- 29
According to the Google Android API, the date should be less than 50K.

- 47,830
- 31
- 106
- 135

- 9
- 1
-
'We recommend that you keep saved state to less than 50k of data.' This is not a limit, this is a recommendation. – Miha_x64 Aug 24 '18 at 08:36
I think that the maximum bundle size is 1024 KiloBytes. In order to transfer large objects among activities, you should try other ways (memory cache, local storage, etc).

- 4,213
- 6
- 45
- 69

- 5,183
- 2
- 34
- 54
-
1
-
1024 bytes. I think I had read it somewhere and also tried in code for more and got a fatal. If I find anything more specific I tell you. – Dimitris Makris Dec 18 '11 at 15:22
-
You won't get a fatal, data seem to be random when you receive it (n4 4.2.2). – Edison Jun 02 '13 at 21:57
-
3This is wrong, 1024 bytes is so little :) The actual limit is should be 1MB but is less most of the time, see this post for more details http://nemanjakovacevic.net/blog/english/2015/03/24/yet-another-post-on-serializable-vs-parcelable/ – Nemanja Kovacevic Mar 25 '15 at 01:48
Yes it has 1MB limit.
You can use Singleton
class to pass data.

- 4,376
- 11
- 45
- 60

- 2,979
- 1
- 22
- 27
-
4Singleton class does not survive app restarts. Android OS can restart your app and try to continue with saved instances and intent bundles. This causes nullpointerexception while returning an app which stayed on background too long. http://www.developerphil.com/dont-store-data-in-the-application-object/ – fthdgn Apr 07 '17 at 11:49
-
Singleton class used only for pass data between activities or fragment – Dayanand Waghmare Apr 02 '18 at 10:05
-
With a correct implementation of the singleton class, it's ok to use @fthdgn – tauitdnmd Apr 05 '19 at 07:33