Starting from API level 33 the getSerializable(String)
method of Bundle class is deprecated. Documentation suggests to use getSerializable(String, Class)
instead. But that function is only available from API level 33.
My current code:
val model = args.getSerializable("key") as? Model
Is this how it should be now?
val model = args.customGetSerializable<Model>("key")
@Suppress("DEPRECATION")
inline fun <reified T : Serializable> Bundle.customGetSerializable(key: String): T? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getSerializable(key, T::class.java)
} else {
getSerializable(key) as? T
}
}