android传值和取值

Intent传值

Intent intent =newIntent(MainActivity.this,Main2Activity.class);

intent.putExtra("name","jack");

intent.putExtra("age",25);

intent.putExtra("address","广州");

Bundle bundle =newBundle();

bundle.putString("code","1021521");

intent.putExtra("bundle",bundle);

startActivity(intent);

Intent获取值并打印出来

Intent intent = getIntent();

String name =intent.getStringExtra("name");

String address = intent.getStringExtra("address");

intage = intent.getIntExtra("age",0);

Bundle bundle = intent.getBundleExtra("bundle");

String code = bundle.getString("code");

Log.i("next","---name-->"+name);

Log.i("next","---age-->"+age);

Log.i("next","---address-->"+address);

Log.i("next","---code-->"+code);

你可能感兴趣的:(android传值和取值)