Sobes.tech
Junior — Middle

What can cause a TransactionTooLargeException in Android?

sobes.tech AI

Answer from AI

The TransactionTooLargeException in Android occurs when the size of data transmitted via Binder (for example, when passing data between Activity or Service through Intent or Bundle) exceeds the IPC limit (usually around 1 MB).

Reasons:

  • Passing large objects or collections in Intent or Bundle.
  • Saving too much data in onSaveInstanceState.

To avoid this error, you should:

  • Pass only the necessary minimal data.
  • Use other mechanisms for transmitting large data, such as files, databases, or Singleton.
  • Use more compact structures for saving state or store data outside of Bundle.

Example:

// Bad: passing a large list in Bundle
bundle.putParcelableArrayList("data", largeList);

// Better: save data in a database or file and pass only the identifier
bundle.putString("dataId", id);