When an activity jumps to another activity through intent, if you want to transfer data at the same time, you can use bundle to put the data in the bundle object, and then add the bundle object to the intent, in this way, parameters are added in batches,
Intent intent =NewIntent ();
Intent. setclass (ex03_10.This, Ex03_10_1.Class);
/*A new bundle object and the data to be passed in*/
Bundle bundle =NewBundle ();
Bundle. putdouble ("height", height );
Bundle. putstring ("sex", sex );
/*Assign the bundle object assign to intent*/
Intent. putextras (bundle );
/*Call activity ex03_10_1*/
Startactivity (intent );
I personally think that the lecture on intelligence is clear.
The bundle class is used to carry data. Similar to map, it is used to store values in the form of key-Value Name-value pairs. Compared with map, it provides various common types of putxxx ()/getxxx () methods, such as: putstring ()/getstring () and putint ()/getint (), putxxx () the getxxx () method is used to get data from the bundle object. The bundle actually uses the hashmap <string, Object> type variable to store the value put by the putxxx () method.
When the getxxx () method of the bundle object is called, The method obtains data from the variable internally and converts the data type. The conversion type is determined by the xxx method, the getxxx () method returns the converted value.
In addition, we can also add a single parameter. This method is more convenient to use, and only a small amountCode.
Intent intent =NewIntent ();
Intent. putextra ("name", "xxxxxx ");
Intent provides the putextra () method after various common types of overload, such as: putextra (string name, string value), putextra (string name, long value), in putextra () the method internally determines whether a bundle object exists in the current intent object. If it does not exist, a new bundle object is created. The value passed in by calling the putextra () method will be stored in the bundle object.