第一种方法:(Intent)
发送方:
Intent intent = new Intent();
intent.putExtra("name", "诸葛亮");
intent.putExtra("age", 50);
intent.putExtra("IQ", 200.0f);
intent.setClass(MainActivity.this, SecondActivity.class);
MainActivity.this.startActivity(intent);
接受方:
Intent intent = getIntent();
String name = intent.getStringExtra("name");
int age = intent.getIntExtra("age", 0);
float IQ = intent.getFloatExtra("IQ", 0.0f);
textview2.setText("name:"+name+",age:"+age+",IQ:"+IQ);
第二种方法:(Bundle)
发送方:
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("name", "乔峰");
bundle.putInt("age", 40);
bundle.putFloat("weight", 70.4f);
intent.putExtras(bundle);
intent.setClass(MainActivity.this, SecondActivity.class);
startActivity(intent);
接受方:
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String name = bundle.getString("name");
int age = bundle.getInt("age");
float weight = bundle.getFloat("weight");
textview.setText(name+","+age+","+weight);