```@Parcelize enum class BaseDestination( @Ign...
# android
z
Copy code
@Parcelize
enum class BaseDestination(
    @IgnoredOnParcel
    val icon: ImageVector,
    @IgnoredOnParcel
    @StringRes
    val label: Int
) : AppDestination {
    HOME(Icons.Default.Home, R.string.home),
    FEED(Icons.Default.Subscriptions, R.string.feed),
    LIBRARY(Icons.Default.VideoLibrary, R.string.library)
}
I'm trying to make it so that it doesnt include the icon and label in parcelization, since those are never gonna change and are not required to be stored. However it says I cannot use IgnoredOnParcel without a default value. What am I supposed to do?
e
what should the value be when it is unparceled?
z
it shouldnt be sent in the parcel, it just should be resolved later in code
e
Bundle.readParcelable<BaseDestination>()
returns...?
if you simply remove the Parcelable/Parcelize from the enum class, then you can't read it as a Parcelable, but other Parcelized classes that use it will use the string representation
but if you want it to be Parcelable on its own, you either have to implement that yourself or work with a Parcelize to make it properties readable and writable or defaulted
t
Instead of parcelize an enum, you just need to use its ordinal value to get the item back
Actually, the enum is a serializable type, we don't need to do anything more
e
Parcelize uses
writeString(enum.name())
and
Enum.valueOf(readString())
, not ordinal and not through Serializable: https://github.com/JetBrains/kotlin/blob/master/plugins/parcelize/parcelize-compiler/parcelize.backend/src/org/jetbrains/kotlin/parcelize/IrParcelSerializers.kt#L154-L176
but either way, to reiterate: if you don't want Parcelize looking into enum properties, don't apply Parcelize to the enum. usages of it in other Parcelize classes will work via built-in enum handling. if you override that by making the enum implement Parcelable then you should be prepared to handle the consequences.
z
I understand. An issue with that though is my AppDeatination interface implements Parcelable
e
then I'd change the enum to a sealed class or manually implement Parcelable