【发布时间】:2022-11-28 23:47:32
【问题描述】:
我想制作一个可打包的数据类来放置捆绑包。此数据类还包含我将调用的函数。但是当我放回应用程序时,parcelize 出现异常。这是我的可打包数据类,
@Parcelize
data class TransactionConfirmData(
val title: String,
@StringRes val cancelBtnLabel: Int
@StringRes val confirmBtnLabel: Int
val confirmElements: Map<String, String>,
val customConfirmDataList: List<CustomTransactionConfirmData> = emptyList(),
val requestMethodId: Int,
@NavigationRes val cancelDestination: Int = 0,
val contentStructure:
TransactionBodyContentCaseTransactionBodyContentCase.BASE_CONFIRM,
@IgnoredOnParcel val onPressFunction: Serializable
) : 可打包 {
fun onPressOkey() = onPressFunction as () -> Unit
companion object {
fun create(
title: String,
@StringRes cancelBtnLabel: Int = R.string.bottom_sheet_behavior
@StringRes confirmBtnLabel: Int = R.string.bottom_sheet_behavior
confirmElements: Map<String, String>,
customConfirmDataList: List<CustomTransactionConfirmData> = emptyList(),
requestMethodId: Int,
@NavigationRes cancelDestination: Int = 0,
contentStructure: TransactionBodyContentCase =
TransactionBodyContentCase.BASE_CONFIRM,
onPressFunction: ()->Unit = {}
): TransactionConfirmData = TransactionConfirmData(
title,
cancelBtnLabel,
confirmBtnLabel,
confirmElements,
customConfirmDataList,
requestMethodId,
cancelDestination,
contentStructure,
onPressFunction as Serializable
)
}
}
但这是行不通的。
【问题讨论】:
标签: android kotlin lambda badparcelableexception