Bundle's Understanding:
A container class that holds the map type of the string and parcelable type data, obtains the corresponding values of various types by holding the Data key (key), and must be obtained by key.
Usage of bundle:
Bundle is equivalent to the map class, is a mapping, with bundle binding data for easy data processing
It mainly acts on the data transfer between the activity.
Testbundle.java
Bundle Bundle = new Bundle ();//Create a handle
Bundle.putstring ("name", nameinfo);//fill nameinfo into handle
Intent mintent = new Intent (testbundle.this,testbundle_getvalue.class);
Mintent.putextras (bundle);
StartActivity (mintent);
Testbundle_getvalue.java
Bundle Bundle = Getintent (). Getextras ()//Get a handle
String namestring=bundle.get ("name");//The value is namestring by the key to "name".
/*
* For related operations
*/
Examples of bundle:
The first activity emits a parameter. Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import android.view.MotionEvent;
public class Testbundle extends activity {
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
}
public boolean ontouchevent (Motionevent event) {
Intent Intent = new Intent ();
Intent.setclass (Testbundle.this, Target.class);
Bundle mbundle = new Bundle ();
Mbundle.putstring ("Data", "Hello, bear");
Intent.putextras (Mbundle);
StartActivity (Intent);
Finish ();
Return Super.ontouchevent (event);
}
}
Second activity, receiving parameters
Import android.app.Activity;
Import Android.os.Bundle;
public class Target extends activity{
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Bundle Bundle = Getintent (). Getextras ();
String data=bundle.getstring ("data");/read out data
Settitle (data);
}
}
In addition, the savedinstancestate in OnCreate (Bundle savedinstancestate) is used to save temporary data before the current activity is switched so that the previous data is displayed on the next return. So if you want to use Bundle savedinstancestate to save temporary data, you should write savedinstancestate in advance in the OnCreate (Bundle savedinstancestate) method. =null the logic of the time. Reference Understanding: Http://blog.sina.com.cn/s/blog_652dd96d0100ug6h.html