Search code examples
androidandroid-intentkotlinsharedpreferencesparcelable

Android The best practice to pass big object between activities?


I want to pass a big object(Parcelable) between two activities, what is the best practice for that? I can't use Intent because of the limitation of Parcelable:

android.os.TransactionTooLargeException: data parcel size 1002388 bytes

So, what is the best practice for that?


Solution

  • The best practice is not passing the whole object through activities or fragments transaction. Better approach to save a file into DB or any local folder and pass to Acitvity/Fragment the link to object (id from DB or URI to file).

    val intent = Intent(this, MainActivity::class.java)
    intent.putExtra(EXTRA_KEY_FILE_ID, fileId)
    startActivity(intent)