1. Introduction
Used for data transmission between different activities
2. Important Methods
Clear(): Clear all stored data in this bundle ing.
Clone(): Clone the current bundle
Containskey(String key): returns the value of the specified key.
Getstring(String key): returns the character of the specified key.
Hasfiledescriptors(): Indicates whether to include any bundled package file descriptor.
Isempty(): Returns true if the binding ing is null.
Putstring(String key, string value): inserts the string value of a given key.
Readfromparcel(Parcel ):Read the content of this parcel.
Remove(String key): removes the value of a specified key.
Writetoparcel(Parcel, int flags ):Write the parcel content
Android2activity. Java
Package android2.test; </P> <p> Import android. app. activity; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. view. view; <br/> Import android. view. view. onclicklistener; <br/> Import android. widget. button; <br/> Import android. widget. edittext; </P> <p> public class android2activity extends activity {</P> <p> private edittext ET = NULL; <br/> private button = NULL; <br/> @ override <br/> Public void oncreate (bundle savedinstancestate) <br/>{< br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> ET = (edittext) findviewbyid (R. id. edit); <br/> button = (button) findviewbyid (R. id. button); <br/> button. setonclicklistener (New buttonlistener (); <br/>}</P> <p> public class buttonlistener implements onclicklistener {</P> <p> Public void onclick (view arg0) {<br/> // todo auto-generated method stub <br/> bundle = new bundle (); <br/> bundle. putstring ("name", et. gettext (). tostring (); <br/> intent = new intent (android2activity. this, bundle. class); <br/> intent. putextras (bundle); <br/> startactivity (intent); <br/>}< br/>
Main. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> <br/> <edittext <br/> Android: id = "@ + ID/edit" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content"/> <br/> <button <br/> Android: Id = "@ + ID/button" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "start"/> <br/> </linearlayout>
Bundle. Java
Package android2.test; </P> <p> Import android. app. activity; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. widget. textview; </P> <p> public class bundle extends activity {<br/> private textview text = NULL; <br/> @ override <br/> Public void oncreate (bundle savedinstancestate) <br/>{< br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. bundle); <br/> intent = getintent (); <br/> bundle = intent. getextras (); <br/> text = (textview) findviewbyid (R. id. text); <br/> text. settext (bundle. getstring ("name"); <br/>}</P> <p >}< br/>
Bundle. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> <br/> <textview <br/> Android: id = "@ + ID/text" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> </linearlayout>