'getSerializableExtra(string!): Serializable?' is deprecated. Deprecated in Java
model = intent.getSerializableExtra("data") as T?
model = intent.getSerializableExtra("data",T::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
model = intent.getSerializableExtra("data",T::class.java)
} else {
model = intent.getSerializableExtra("data") as T?
}
// API 33 이후 getSerializable()가 deprecated 되어서 만든 확장함수
fun <T: Serializable> Intent.intentSerializable(key: String, clazz: Class<T>): T? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
this.getSerializableExtra(key, clazz)
} else {
this.getSerializableExtra(key) as T?
}
}
model = intent.intentSerializable("data", Model::class.java)
확장함수 부분 유용하네요. 글 잘보고 갑니다.