Bundle is null android

Bundle in Android with Example

It is known that Intents are used in Android to pass to the data from one activity to another. But there is one another way, that can be used to pass the data from one activity to another in a better way and less code space ie by using Bundles in Android. Android Bundles are generally used for passing data from one activity to another. Basically here concept of key-value pair is used where the data that one wants to pass is the value of the map, which can be later retrieved by using the key. Bundles are used with intent and values are sent and retrieved in the same fashion, as it is done in the case of Intent. It depends on the user what type of values the user wants to pass, but bundles can hold all types of values (int, String, boolean, char) and pass them to the new activity.

The following are the major types that are passed/retrieved to/from a Bundle:

putInt(String key, int value), getInt(String key, int value)

putString(String key, String value), getString(String key, String value)

putStringArray(String key, String[] value), getStringArray(String key, String[] value)

putChar(String key, char value), getChar(String key, char value)

putBoolean(String key, boolean value), getBoolean(String key, boolean value)

Using the Bundle in the Android App

The bundle is always used with Intent in Android. Now to use Bundle writes the below code in the MainActivity.

Источник

Bundle Class

Definition

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

A mapping from String keys to various Parcelable values.

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Constructs a new, empty Bundle.

Constructs a new, empty Bundle.

Constructs a new, empty Bundle.

Constructs a new, empty Bundle.

Constructs a new, empty Bundle.

Properties

Returns the runtime class of this Object .

(Inherited from Object) ClassLoader

Return the ClassLoader currently associated with this Bundle.

An unmodifiable Bundle that is always #isEmpty() empty .

The handle to the underlying Android instance.

(Inherited from Object) HasFileDescriptors

Reports whether the bundle contains any parcelled file descriptors.

Returns true if the mapping of this Bundle is empty, false otherwise.

JniIdentityHashCode (Inherited from Object) JniPeerMembers PeerReference (Inherited from Object) ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from BaseBundle) ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from BaseBundle)

Methods

Removes all elements from the mapping of this Bundle.

Clones the current Bundle.

Returns true if the given key is contained in the mapping of this Bundle.

Make a deep copy of the given bundle.

Report the nature of this Parcelable’s contents

Dispose() (Inherited from Object) Dispose(Boolean) (Inherited from Object) Equals(Object)

Indicates whether some other object is «equal to» this one.

(Inherited from Object) Get(String)

Returns the entry with the given key as an object.

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.

Returns the value associated with the given key, or false if no mapping of the desired type exists for the given key.

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

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.

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.

Читайте также:  Музыкальный проигрыватель для андроида без рекламы

Returns the value associated with the given key, or (byte) 0 if no mapping of the desired type exists for the given key.

Returns the value associated with the given key, or (byte) 0 if no mapping of the desired type exists for the given key.

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.

Returns the value associated with the given key, or (char) 0 if no mapping of the desired type exists for the given key.

Returns the value associated with the given key, or (char) 0 if no mapping of the desired type exists for the given key.

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.

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.

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.

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.

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.

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.

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.

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.

Returns the value associated with the given key, or 0.0 if no mapping of the desired type exists for the given key.

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

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.

Returns the value associated with the given key, or 0.

Returns the value associated with the given key, or 0.

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.

Returns a hash code value for the object.

(Inherited from Object) GetInt(String)

Returns the value associated with the given key, or 0 if no mapping of the desired type exists for the given key.

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

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.

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.

Returns the value associated with the given key, or 0L if no mapping of the desired type exists for the given key.

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

Читайте также:  Обновленная версия вконтакте для андроид

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.

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.

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.

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.

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.

Returns the value associated with the given key, or (short) 0 if no mapping of the desired type exists for the given key.

Returns the value associated with the given key, or (short) 0 if no mapping of the desired type exists for the given key.

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.

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.

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.

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.

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.

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

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.

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.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object) KeySet()

Returns a Set containing the Strings used as keys in this Bundle.

Wakes up a single thread that is waiting on this object’s monitor.

(Inherited from Object) NotifyAll()

Wakes up all threads that are waiting on this object’s monitor.

(Inherited from Object) PutAll(Bundle)

Inserts all mappings from the given Bundle into this Bundle.

Inserts all mappings from the given PersistableBundle into this BaseBundle.

(Inherited from BaseBundle) PutBinder(String, IBinder)

Inserts an IBinder value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a Boolean value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a boolean array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a Bundle value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a byte value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a byte array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a char value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a char array value into the mapping of this Bundle, replacing any existing value for the given key.

Читайте также:  Zona для скачивания всего для андроид

Inserts a CharSequence value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a CharSequence value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a CharSequence array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a CharSequence array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts an ArrayList value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a double value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a double array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a float value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a float array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts an int value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts an int array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts an ArrayList value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a long value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a long array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a Parcelable value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts an array of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a List of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a Serializable value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a short value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a short array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a Size value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a SizeF value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a SparceArray of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a String value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts a String array value into the mapping of this Bundle, replacing any existing value for the given key.

Inserts an ArrayList value into the mapping of this Bundle, replacing any existing value for the given key.

Reads the Parcel contents into this Bundle, typically in order for it to be passed through an IBinder connection.

Removes any entry with the given key from the mapping of this Bundle.

Changes the ClassLoader this Bundle uses when instantiating objects.

Sets the Handle property.

(Inherited from Object) Size()

Returns the number of mappings contained in this Bundle.

Returns a string representation of the object.

(Inherited from Object) UnregisterFromRuntime() (Inherited from Object) Wait()

Causes the current thread to wait until another thread invokes the java.lang.Object#notify() method or the java.lang.Object#notifyAll() method for this object.

(Inherited from Object) Wait(Int64)

Causes the current thread to wait until another thread invokes the java.lang.Object#notify() method or the java.lang.Object#notifyAll() method for this object.

(Inherited from Object) Wait(Int64, Int32)

Causes the current thread to wait until another thread invokes the java.lang.Object#notify() method or the java.lang.Object#notifyAll() method for this object.

(Inherited from Object) WriteToParcel(Parcel, ParcelableWriteFlags)

Writes the Bundle contents to a Parcel, typically in order for it to be passed through an IBinder connection.

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

Performs an Android runtime-checked type conversion.

Источник

Оцените статью