Yoni
Yoni

Reputation: 1356

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?

Upvotes: 1

Views: 1054

Answers (1)

Oleg Kuzmin
Oleg Kuzmin

Reputation: 301

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)

Upvotes: 2

Related Questions