I am passing data via intent with Parcelable and receiving using getParcelableExtra . However getParcelableExtra seems to be deprecated, How do I fix the deprecation warning in this code? Alternatively, are there any other options for doing this? . I am using compileSdkVersion 33.
Code snippet:
var data = intent.getParcelableExtra("data")
CodePudding user response:
Now we need to use getParcelableExtra()
with the type-safer class added to API 33
SAMPLE CODE
val userData = if (VERSION.SDK_INT >= 33) {
intent.getParcelableExtra("DATA", User::class.java)
} else {
intent.getParcelableExtra<User>("DATA")
}
CodePudding user response:
As described in the official documentation, getParcelableExtra
was deprecated in API level 33.
So check if the API LEVEL is >= 33 or change the method,
...
if (Build.VERSION.SDK_INT >= 33) {
data = getParcelableExtra (String name, Class<T> clazz)
}else{
data = intent.getParcelableExtra("data")
}