diff --git a/core/api/current.txt b/core/api/current.txt index 4f2a07bdaf347..d791342b206fc 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -9755,12 +9755,16 @@ package android.content { method @Nullable public long[] getLongArrayExtra(String); method public long getLongExtra(String, long); method @Nullable public String getPackage(); - method @Nullable public android.os.Parcelable[] getParcelableArrayExtra(String); - method @Nullable public java.util.ArrayList getParcelableArrayListExtra(String); - method @Nullable public T getParcelableExtra(String); + method @Deprecated @Nullable public android.os.Parcelable[] getParcelableArrayExtra(String); + method @Nullable public T[] getParcelableArrayExtra(@Nullable String, @NonNull Class); + method @Deprecated @Nullable public java.util.ArrayList getParcelableArrayListExtra(String); + method @Nullable public java.util.ArrayList getParcelableArrayListExtra(@Nullable String, @NonNull Class); + method @Deprecated @Nullable public T getParcelableExtra(String); + method @Nullable public T getParcelableExtra(@Nullable String, @NonNull Class); method @Nullable public String getScheme(); method @Nullable public android.content.Intent getSelector(); - method @Nullable public java.io.Serializable getSerializableExtra(String); + method @Deprecated @Nullable public java.io.Serializable getSerializableExtra(String); + method @Nullable public T getSerializableExtra(@Nullable String, @NonNull Class); method @Nullable public short[] getShortArrayExtra(String); method public short getShortExtra(String, short); method @Nullable public android.graphics.Rect getSourceBounds(); diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 8a5e097c2a738..22c838c2f7bbb 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -8581,12 +8581,31 @@ public class Intent implements Parcelable, Cloneable { * @return the value of an item previously added with putExtra(), * or null if no Parcelable value was found. * + * @deprecated Use the type-safer {@link #getParcelableExtra(String, Class)} starting from + * Android {@link Build.VERSION_CODES#TIRAMISU}. + * * @see #putExtra(String, Parcelable) */ + @Deprecated public @Nullable T getParcelableExtra(String name) { return mExtras == null ? null : mExtras.getParcelable(name); } + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param clazz The type of the object expected. + * + * @return the value of an item previously added with putExtra(), + * or null if no Parcelable value was found. + * + * @see #putExtra(String, Parcelable) + */ + public @Nullable T getParcelableExtra(@Nullable String name, @NonNull Class clazz) { + return mExtras == null ? null : mExtras.getParcelable(name, clazz); + } + /** * Retrieve extended data from the intent. * @@ -8595,12 +8614,33 @@ public class Intent implements Parcelable, Cloneable { * @return the value of an item previously added with putExtra(), * or null if no Parcelable[] value was found. * + * @deprecated Use the type-safer {@link #getParcelableArrayExtra(String, Class)} starting from + * Android {@link Build.VERSION_CODES#TIRAMISU}. + * * @see #putExtra(String, Parcelable[]) */ + @Deprecated public @Nullable Parcelable[] getParcelableArrayExtra(String name) { return mExtras == null ? null : mExtras.getParcelableArray(name); } + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param clazz The type of the items inside the array. This is only verified when unparceling. + * + * @return the value of an item previously added with putExtra(), + * or null if no Parcelable[] value was found. + * + * @see #putExtra(String, Parcelable[]) + */ + @SuppressLint({"ArrayReturn", "NullableCollection"}) + public @Nullable T[] getParcelableArrayExtra(@Nullable String name, + @NonNull Class clazz) { + return mExtras == null ? null : mExtras.getParcelableArray(name, clazz); + } + /** * Retrieve extended data from the intent. * @@ -8610,12 +8650,35 @@ public class Intent implements Parcelable, Cloneable { * putParcelableArrayListExtra(), or null if no * ArrayList value was found. * + * @deprecated Use the type-safer {@link #getParcelableArrayListExtra(String, Class)} starting + * from Android {@link Build.VERSION_CODES#TIRAMISU}. + * * @see #putParcelableArrayListExtra(String, ArrayList) */ + @Deprecated public @Nullable ArrayList getParcelableArrayListExtra(String name) { return mExtras == null ? null : mExtras.getParcelableArrayList(name); } + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param clazz The type of the items inside the array list. This is only verified when + * unparceling. + * + * @return the value of an item previously added with + * putParcelableArrayListExtra(), or null if no + * ArrayList value was found. + * + * @see #putParcelableArrayListExtra(String, ArrayList) + */ + @SuppressLint({"ConcreteCollection", "NullableCollection"}) + public @Nullable ArrayList getParcelableArrayListExtra(@Nullable String name, + @NonNull Class clazz) { + return mExtras == null ? null : mExtras.getParcelableArrayList(name, clazz); + } + /** * Retrieve extended data from the intent. * @@ -8624,12 +8687,31 @@ public class Intent implements Parcelable, Cloneable { * @return the value of an item previously added with putExtra(), * or null if no Serializable value was found. * + * @deprecated Use the type-safer {@link #getSerializableExtra(String, Class)} starting from + * Android {@link Build.VERSION_CODES#TIRAMISU}. + * * @see #putExtra(String, Serializable) */ public @Nullable Serializable getSerializableExtra(String name) { return mExtras == null ? null : mExtras.getSerializable(name); } + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param clazz The type of the object expected. + * + * @return the value of an item previously added with putExtra(), + * or null if no Serializable value was found. + * + * @see #putExtra(String, Serializable) + */ + public @Nullable T getSerializableExtra(@Nullable String name, + @NonNull Class clazz) { + return mExtras == null ? null : mExtras.getSerializable(name, clazz); + } + /** * Retrieve extended data from the intent. *