I've been using Serializable for a while now in Android to pass data between 2 Activities. However, I recently read about Parcelable. Do they work in the same way and which is the best/efficient way to pass data/custom Objects between Activities/Fragments? I've seen that there is some setup code required to setup a Parcelable class which I haven't been able to figure out yet. Please Advice. Thanks.
Asked
Active
Viewed 29 times
0
-
Parcelable is from Android, Serializable is from Java. I don't know the main differences between them, but I usually use Parcelable because it is from Android and there is a lot of documentation with Parcelable and Android. – R0ck Nov 25 '22 at 17:56
-
FWIW, I cover `Parcelable` in [this section](https://commonsware.com/Jetpack/pages/chap-process-008.html) of [this free book](https://commonsware.com/Jetpack) – CommonsWare Nov 25 '22 at 17:57
-
If you are using Kotlin, you can use kotlin-parcelize to avoid that Parcelable implementation that you talking about. You just need to add "kotlin-parcelize" in your plugins on gradle app file. After that, just use @Parcelize annotation in your data class and extent Parcelable. It should work properly. – R0ck Nov 25 '22 at 17:58