android中intent说明

Android 中各个组件主要是通过Intent来通讯。
Intent负责对应用中一次操作的动作、动作涉及数据、附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组件,将 Intent传递给调用的组件,并完成组件的调用。
因此,Intent在这里起着一个媒体中介的作用,专门提供组件互相调用的相关信息,实现调用者与被调用者之间的解耦。

 

1.intent数据传递

 

intent中的数据传递,我们可以采用两中方式来实现,如果是简单的数据类型的数据可以直接采用Bundle来传递,而且bundle可以传递多个值,具体实现如下:

 

Bundle bundle =new Bundle();
bundle.putString("userName", "zhangsan");
bundle.putString("password", "123456");
intent.putExtras(bundle);

 

如果是传递集合或者对象那么需要采用intent中提供的putExtra方法,实现如下:

 

UserVO userVO =new UserVO(); //该对象需要实现Serializable接口
userVO.setUserName("wuhen");
userVO.setPassword("ling");
intent.putExtra("userVO", userVO);

 

2.关于intent的申明有显示申明和隐式申明,采用显示的申明非常的简单

 

Intent intent = new Intent(ActivityTestActivity.this, ActivityB.class);
startActivity(intent);

 

如果是隐式的申明稍微比较复杂点

Intent intent =new Intent();
intent.setClass(ActivityTestActivity.this, ActivityB.class);

或者设置setComponent


android提供了许多标注的action,例如打电话,发邮件,发短息等等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值