# New Method Simplifies Parcelable Usage in Android

Simplify Parcelable processes with Kotlinx.serialization.

- **Source:** [Chris Keenan Codes](https://brifing.si/source/0d4c37c2-b3ff-4b12-9334-fca791d870d4)
- **Published:** 2021-01-18
- **Topic:** [Software & Engineering](https://brifing.si/c/engineering)
- **Original article:** <https://chrynan.codes/android-parcelable-theres-a-better-way/>
- **On Brifing:** https://brifing.si/s/b1b03e80-d17d-44af-bd1d-a167b0d1f9b6

## Challenges of Parcelable

Implementing the Parcelable interface in Android requires functions like describeContents and writeToParcel, as well as creating a CREATOR field. This process is complex and error-prone, especially since the correct order of data reading/writing is critical.

## Java Serializable Alternative

The Java Serializable interface offers a simpler solution than Parcelable. However, due to its use of reflection, it leads to performance degradation. This drawback is unacceptable in resource-constrained environments like Android.

## Kotlin @Parcelize Solution

The @Parcelize annotation from Kotlin Android Extensions greatly simplifies Parcelable implementation. However, the need to write custom Parcelers for complex objects remains, and it is limited in multiplatform projects.

## Multiplatform Support: moko-parcelize

IceRock Development's moko-parcelize library brings @Parcelize functionality to Kotlin Multiplatform. This allows model classes in shared modules to be easily made parcelable.

## Kotlinx.serialization Integration

The Kotlinx.serialization library enables working with formats like JSON and Protobuf. However, the requirement to write both KSerializer and Parceler leads to code duplication and complexity.

## Significance of the New Approach

The new Kotlinx.serialization-based parcelable library significantly improves developer experience by supporting both Parcelable and other formats with a single serialization mechanism.

## Sources covering this story

- https://chrynan.codes/android-parcelable-theres-a-better-way/ — 

---

_Summary written by Brifing from the original reporting. Copyright in the original article belongs to its publisher; read the full piece at the link above._
