Passing enum or object through an intent the best solution
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The best way to pass data through an Android Intent depends on what the data actually is. For enums, a stable string or dedicated code is usually enough. For small app-internal objects, Parcelable is the normal Android-friendly choice. For large or important objects, passing only an ID and reloading the data in the destination is usually safer.
Pass Enums as Stable Values
Enums are small and finite, so they do not need heavyweight serialization. The safest default is to pass the enum name rather than its ordinal:
Then read it back:
Why use name instead of ordinal? Because ordinals change if you reorder or insert enum constants. Names are far more stable for cross-activity communication.
Use Parcelable for Small Custom Objects
For custom objects that really should travel with the Intent, Parcelable is the Android-native option. In Kotlin, @Parcelize makes this very practical:
Put it into the intent:
And receive it:
This is usually the best answer for small, self-contained transfer objects.
Pass IDs for Large or Important Domain Objects
Even though Parcelable works, it is often the wrong choice for large domain objects. If the target screen can load the data again from a repository, database, or network layer, pass only the identifier:
Then in the destination:
This pattern is more resilient because:
- the intent payload stays small
- the destination gets fresh data
- process recreation is easier to reason about
- version mismatches between activities matter less
For anything that already has a durable identity, passing the ID is often cleaner than serializing the whole object.
Why Serializable Is Usually Not the Best Default
Java Serializable can work, but it is usually not the best Android default for intent extras. It is more generic, often slower, and less Android-specific than Parcelable.
That does not mean it is forbidden. It means that if you are designing an Android app boundary intentionally, Parcelable or ID passing is usually the better fit.
Keep Intent Payloads Small
It is tempting to use intents as a generic object transport layer. That becomes risky quickly. Large payloads can cause binder transaction issues, make process recreation harder, and create stale-data problems between screens.
As a rule:
- enum: pass a stable name or code
- small DTO:
Parcelable - large entity: pass an ID
That simple rule covers most real applications well.
Common Pitfalls
The most common mistake is passing enum ordinals. They are compact, but not stable under refactoring.
Another pitfall is sending large complex objects through the intent when the destination could just load them from a shared source using an ID. That creates bigger payloads and more fragile screen boundaries.
It is also easy to overuse Serializable because it looks simple at first. In Android, Parcelable is usually the more intentional choice for small transport objects.
Finally, remember that intent extras are not a substitute for a proper data layer. If the object is authoritative application state, the destination should often reload it rather than trust a stale serialized copy.
Summary
- Pass enums as stable names or codes, not ordinals.
- Use
Parcelablefor small Android transfer objects. - Prefer passing IDs for large or important domain objects.
- Keep intent extras small and purpose-built.
- Choose the transport format based on data stability and payload size, not just on what is easiest to serialize.

