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 file descriptor.
IsEmpty (): returns true if the binding ing is null.
PutString (String key, String value): inserts a String value of a given key.
ReadFromParcel (Parcel parcel): Read the content of this parcel.
Remove (String key): removes the value of a specified key.
WriteToParcel (Parcel parcel, int flags): Write the parcel content.
Android2Activity. java
Package Android2.test;
Import android. app. Activity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. EditText;
Public class Android2Activity extends Activity {
Private EditText et = null;
Private Button button = null;
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Et = (EditText) findViewById (R. id. edit );
Button = (Button) findViewById (R. id. button );
Button. setOnClickListener (new ButtonListener ());
}
Public class ButtonListener implements OnClickListener {
Public void onClick (View arg0 ){
// TODO Auto-generated method stub
Bundle bundle = new Bundle ();
Bundle. putString ("Name", et. getText (). toString ());
Intent intent = new Intent (Android2Activity. this, bundle. class );
Intent. putExtras (bundle );
StartActivity (intent );
}
}
}
Main. xml
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
<EditText
Android: id = "@ + id/edit"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"/>
<Button
Android: id = "@ + id/button"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "start"/>
</LinearLayout>
Bundle. java
Package Android2.test;
Import android. app. Activity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. widget. TextView;
Public class bundle extends Activity {
Private TextView text = null;
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. bundle );
Intent intent = getIntent ();
Bundle bundle = intent. getExtras ();
Text = (TextView) findViewById (R. id. text );
Text. setText (bundle. getString ("Name "));
}
}
Bundle. xml
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
<TextView
Android: id = "@ + id/text"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
/>
</LinearLayout>
From sunset hut