In Android, since intent can pass key-value pair data, why should intent and bundle be used together?
大家讲道理2017-05-16 13:35:37
0
3
836
As mentioned in the title, both bundle and intent can store key-value pair data. In logarithmic cases, just use intent directly. Why is there such a combination of intent+bundle?
The first floor has already answered it correctly, I just posted the source code:
/**
* Add extended data to the intent. The name must include a package
* prefix, for example the app com.android.contacts would use names
* like "com.android.contacts.ShowAll".
*
* @param name The name of the extra data, with package prefix.
* @param value The String data value.
*
* @return Returns the same Intent object, for chaining multiple calls
* into a single statement.
*
* @see #putExtras
* @see #removeExtra
* @see #getStringExtra(String)
*/
public Intent putExtra(String name, String value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putString(name, value);
return this;
}
Even if you use intent to pass it, a bundle will be automatically generated.
So in fact, bundles are used
The first floor has already answered it correctly, I just posted the source code:
It seems that the bundle can transfer many data types?