Parcelable vs Serializable

Lifecycle and app components Junior Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Pick the fix

You need to pass a small Filter object to another Activity. What's the best choice?

Options
Hint 1 of 1

Which one is built for Binder transfer?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Annotate it with @Parcelize and implement Parcelable

Correct. Generated, fast, and made for Intents.

Why not the others?
  • B Implement Serializable. It works but is slower and bulkier.
  • C Convert it to a JSON string by hand every time. It works but adds code and cost for no benefit here.
  • D Put it in a global singleton. It won't survive process death.

30-second answer

Serializable is the standard Java interface: easy to add, but it uses reflection and is slow and produces large output. Parcelable is Android's own interface, designed for fast Binder transfer, and the @Parcelize plugin generates the code for you. For Intents and saved state, use @Parcelize. For storage or network, use kotlinx.serialization or JSON, not either of these.

Practise saying it · 30 s. No recording, just a timer

Compare Parcelable and Serializable.

Say your answer out loud, then check which of these points you covered:

  • Serializable is Java, reflection, slow
  • Parcelable is Android, fast
  • Use @Parcelize
  • Never persist Parcels

Deep dive

@Parcelize comes from the kotlin-parcelize Gradle plugin.

Parcel data is not a stable format across app versions; never persist it to disk.

Navigation's type-safe routes use kotlinx.serialization, not Parcelable.

Keep parceled objects small for the same Binder limit reasons.

@Parcelize Compile-checked · Kotlin 2.4.21
@Parcelize
data class Filter(val query: String, val minPrice: Int) : Parcelable

Common mistakes

  • Calling Serializable 'Android-specific' (it's from Java).
  • Writing Parcel code by hand in Kotlin.
  • Saving Parcel bytes to a file.

Senior take & follow-ups

Get the origins right (Java vs Android), then speed, then the storage warning.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why can't you store Parcel bytes?

    Show hint

    The format isn't stable across versions or devices.

  2. What do type-safe Navigation routes use?

    Show hint

    kotlinx.serialization.

Suggest a fix if something here is wrong or out of date.