How to send an object from one Android Activity to another using Intents?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Passing structured data between Android activities is common in navigation flows such as details screens, checkout flows, and profile editing. Intents can carry custom objects, but the object must be encoded in a form Android can marshal across process boundaries. This article covers the practical choice between Parcelable and Serializable, with Java examples and safety checks.
Core Sections
Choose Parcelable for App Performance
Android recommends Parcelable for frequent object passing because it avoids reflection-heavy serialization overhead. Serializable is simpler but often slower and can allocate more temporary objects.
Use Parcelable when:
- object transfer is frequent
- object size is moderate to large
- performance on lower-end devices matters
Use Serializable for quick prototypes or very small low-frequency transfers.
Define a Parcelable Model in Java
Keep property order consistent between writeToParcel and parcel constructor.
Send the Object with Intent Extras
Use explicit constant keys to avoid typo bugs.
Receive the Object Safely
In the destination activity, read the value and handle nulls defensively.
Null handling is important because activities can be launched from multiple paths.
Passing Lists of Objects
If you need multiple models, pass an ArrayList of parcelables.
Receive in destination:
Size and Lifecycle Considerations
Intent extras are not designed for large payloads. If your object graph is large, pass an ID and fetch data from:
- Room database
- repository cache
- network layer
This keeps navigation robust and avoids binder transaction-size issues.
Also consider process recreation. Persist required identifiers in savedInstanceState so you can recover after configuration change or process death.
Quick Test Strategy
Instrumented test ideas:
- launch destination with valid parcelable and assert UI fields
- launch without extra and verify fallback behavior
- launch with edge values such as empty strings
These tests catch regressions when model fields change.
Common Pitfalls
- Using
Serializablefor high-frequency transfers and then hitting avoidable UI lag. - Mismatching parcel read and write order, which corrupts deserialized values.
- Hardcoding extra keys in multiple places, causing typo-related nulls.
- Sending large object graphs in extras instead of passing stable identifiers.
- Skipping null checks when reading extras in destination activities.
Summary
- Use
Parcelableas the default for passing custom objects between Android activities. - Keep parcel serialization order consistent and centralize extra keys.
- Read extras defensively and support alternate launch paths.
- Pass IDs, not large payloads, when data size grows.
- Add focused tests to protect navigation data contracts as models evolve.

