getparcelableextra deprecated
时间: 2023-07-28 16:08:54 浏览: 213
discourse-group-timezones
Yes, the `getParcelableExtra` method is deprecated in newer versions of Android. Instead, you should use the `getParcelableExtra` method from the `Intent` class.
Here's an example of how you can retrieve a `Parcelable` extra from an intent using the updated method:
```java
Intent intent = getIntent();
YourParcelableClass parcelable = intent.getParcelableExtra("your_key");
```
Make sure to replace `"your_key"` with the actual key you used when putting the extra into the intent.
If you're targeting Android API level 30 or higher, you can also use the new `getParcelableExtraOrNull` method, which returns `null` if the extra is not found:
```java
Intent intent = getIntent();
YourParcelableClass parcelable = intent.getParcelableExtraOrNull("your_key");
```
Remember to update your code accordingly to use the recommended methods and avoid using deprecated ones.
阅读全文