The examples in this article describe two implementations of the intent additional data for Android. Share to everyone for your reference. Specifically as follows:
The first method used to bulk add data to intent:
Intent Intent = new Intent ();
Bundle Bundle = new Bundle ();
This class is used to carry data
bundle.putstring ("name", "Lin Yi-chin");
Intent.putextras (bundle);
Additional data is intended to be appended to the intention that the data already in the original intent is not lost, but the data with the same name as the key is replaced
The second way of writing: This type of writing is equivalent to the above, but this way of writing is to add data into the intent, which is easy to use, and only need to write a small number of code.
Intent Intent = new Intent ();
Intent.putextra ("name", "Lin Yi-chin");
Intent provides a Putextra () method after various common type overloads, such as Putextra (string name, String value), Putextra (string name, Long value), in Putextra () The method internally determines whether a bundle object already exists inside the current intent object, and if it does not exist, a new bundle object is created, and subsequent calls to the Putextra () method are stored in the bundle object, followed by intent Putextra ( String name, String value) method code fragment:
public class Intent implements parcelable {
private Bundle Mextras;
Public Intent Putextra (string name, String value) {
if (Mextras = null) {
Mextras = new Bundle ();
}
Mextras.putstring (name, value);
return this;
}
I hope this article will help you with your Android program.