android--Activity值传递

本文深入探讨了在Android应用开发中使用Intent进行Activity间跳转的过程,包括如何在MainActivity中创建Intent并设置额外参数,以及如何在NextActivity中接收并解析这些参数。通过实例演示了如何利用Bundle来实现更复杂的数据传递,并介绍了在LogCat中配置过滤器以方便查看NextActivity的日志信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

intent用法:

MainActivity中

  Intent intent=new Intent(MainActivity.this,NextActivity.class);
    intent.putExtra("name", "Tom");
    intent.putExtra("age", 23);

    //学习了Bundle的用法
    Bundle bundle=new Bundle();
    bundle.putString("code", "124");
    intent.putExtra("bundle", bundle);
    startActivity(intent);

NextActivity中:

  Intent intent=getIntent();
  String name=intent.getStringExtra("name");
  Log.i(TAG, "--name->"+name);
  int age=intent.getIntExtra("age", 0);
  Log.i(TAG, "--age-"+age);
  Bundle bundle=intent.getBundleExtra("bundle");
  String code=bundle.getString("code");
  Log.i(TAG,"--code-"+code);

另外配置log的方法:

private final String TAG="NextActivity";

在window--showview--other--LogCat,create filter中,filter name:"NextActivity",by Log Tag:"NextActivity",by Log Level:info

 

转载于:https://www.cnblogs.com/zaqn/p/3545000.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值