TransactionTooLargeexception reflects limitations of IPC mechanism on Android, in the way, how data are transfered between processes.
Since you are sharing data between activities, given restrictions you have, following possibilities came to my mind:
- keeping data in a singleton instance of repository (which takes reponsibility for reloading of data in case, they get lost during recreating of activities etc.) and trafering just unique indetifier(or identifiers)
- reduce size of data by simple data transformation or compression(integer instead of float, long for Date etc.)
- as pointed out by @nsk, with an event bus you can overcome limitations of IPC, but this brings a "fun" with activity's lifecycle
- kotlin brings
kotlinx.serialization
into the game, not much experience on my side, but sure something you can evaluate(performance and data size)
Independently of selected solution to your problem, I would recomend to use Parcelable
instead of Seriazable
for Intent
, mainly for performance reasons, reflection is still an issue and I can barely remember having lint warnings. For Parcelable
with Kotlin there is indeed a handy solutionwith Parcelize
annotation provided by Kotlin Android Extensions library.
Simple object looks like this
@Parcelize
class Student(val name: String, val year: Int) : Parcelable