diff --git a/api/current.txt b/api/current.txt index 86353d17f9b10..e65f6226493d9 100644 --- a/api/current.txt +++ b/api/current.txt @@ -15862,6 +15862,7 @@ package android.os { method public boolean containsKey(java.lang.String); method public int describeContents(); method public java.lang.Object get(java.lang.String); + method public android.os.IBinder getBinder(java.lang.String); method public boolean getBoolean(java.lang.String); method public boolean getBoolean(java.lang.String, boolean); method public boolean[] getBooleanArray(java.lang.String); @@ -15906,6 +15907,7 @@ package android.os { method public boolean isEmpty(); method public java.util.Set keySet(); method public void putAll(android.os.Bundle); + method public void putBinder(java.lang.String, android.os.IBinder); method public void putBoolean(java.lang.String, boolean); method public void putBooleanArray(java.lang.String, boolean[]); method public void putBundle(java.lang.String, android.os.Bundle); diff --git a/core/java/android/os/Bundle.java b/core/java/android/os/Bundle.java index 65eefcbeeff35..18a0018a22c8b 100644 --- a/core/java/android/os/Bundle.java +++ b/core/java/android/os/Bundle.java @@ -741,6 +741,25 @@ public final class Bundle implements Parcelable, Cloneable { mMap.put(key, value); } + /** + * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + *

You should be very careful when using this function. In many + * places where Bundles are used (such as inside of Intent objects), the Bundle + * can live longer inside of another process than the process that had originally + * created it. In that case, the IBinder you supply here will become invalid + * when your process goes away, and no longer usable, even if a new process is + * created for you later on.

+ * + * @param key a String, or null + * @param value an IBinder object, or null + */ + public void putBinder(String key, IBinder value) { + unparcel(); + mMap.put(key, value); + } + /** * Inserts an IBinder value into the mapping of this Bundle, replacing * any existing value for the given key. Either key or value may be null. @@ -749,7 +768,7 @@ public final class Bundle implements Parcelable, Cloneable { * @param value an IBinder object, or null * * @deprecated - * @hide + * @hide This is the old name of the function. */ @Deprecated public void putIBinder(String key, IBinder value) { @@ -1536,6 +1555,28 @@ public final class Bundle implements Parcelable, Cloneable { } } + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return an IBinder value, or null + */ + public IBinder getBinder(String key) { + unparcel(); + Object o = mMap.get(key); + if (o == null) { + return null; + } + try { + return (IBinder) o; + } catch (ClassCastException e) { + typeWarning(key, o, "IBinder", e); + return null; + } + } + /** * Returns the value associated with the given key, or null if * no mapping of the desired type exists for the given key or a null @@ -1545,7 +1586,7 @@ public final class Bundle implements Parcelable, Cloneable { * @return an IBinder value, or null * * @deprecated - * @hide + * @hide This is the old name of the function. */ @Deprecated public IBinder getIBinder(String key) {