发送端:
Intent intent = new Intent(MainActivity.this,FirstActivity.class);
Bundle data = new Bundle();
data.putString(NAME_KEY,"zhangsan");//将数据放入bundle
data.putInt(AGE_KEY,25);
data.putBoolean(IS_FEMALE_KEY,false);
intent.putExtras(data);
startActivity(intent);
接收端:
Bundle data = getIntent().getExtras();//从bundle中取出数据
String name = data.getString(NAME_KEY);
int age = data.getInt(AGE_KEY);
boolean isfemale = data.getBoolean(IS_FEMALE_KEY);
Log.d("TAG","waname = "+name);
Log.d("TAG","waage = "+age);
Log.d("TAG","waisfemale = "+isfemale);
/* Bundle bundle = getIntent().getExtras(); //得到传过来的bundle
boolean data = bundle.getBoolean("isConnected");
button2.setText("MainActivity连接=="+data);*/
button2.setText("连接=="+"waname = "+name+"waage = "+age+"waisfemale = "+isfemale);