1. MainActivity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button botton3 = (Button)findViewById(R.id.button1);
botton3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, ShowActivity.class);
intent.putExtra("name", "雨松MOMO");
intent.putExtra("age", 25);
intent.putExtra("boy", true);
Bundle bundle = new Bundle();
bundle.putString("b_name", "小可爱");
bundle.putInt("b_age", 23);
bundle.putBoolean("b_boy", false);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
}
2. ShowActivity
public class ShowActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.my);
Intent intent = getIntent();
String name = intent.getStringExtra("name");
int age = intent.getIntExtra("age", 0);
boolean isboy = intent.getBooleanExtra("boy", false);
TextView textView0 = (TextView)findViewById(R.id.textView1);
textView0.setText("姓名 " + name + "年龄 " + age + "男孩? " + isboy);
Bundle bundle = intent.getExtras();
name = bundle.getString("b_name");
age = bundle.getInt("b_age",0);
isboy = bundle.getBoolean("b_boy", false);
TextView textView1 = (TextView)findViewById(R.id.textView2);
textView1.setText("姓名 " + name + "年龄 " + age + "男孩? " + isboy);
super.onCreate(savedInstanceState);
}
}