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);

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容