FirstMainActivity:
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent=new Intent(FirstMainActivity.this,SecondMainActivity.class);
//intent.putExtra("data", "hello second");
Bundle bundle=new Bundle();
bundle.putString("name", "高振");
bundle.putInt("age", 22);
//intent.putExtras(bundle);
intent.putExtra("data", bundle);
startActivity(intent);
}
});
SecondMainActivity:
private TextView textView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second_main);
Intent intent=getIntent();
//Bundle bundle=intent.getExtras();
Bundle bundle=intent.getBundleExtra("data");
textView1=(TextView) findViewById(R.id.textView1);
//textView1.setText(intent.getStringExtra("data"));
textView1.setText(String.format("name=%s,age=%d", bundle.getString("name"),bundle.getInt("age")));
}