Android期末考考前盘点(六):1000%用到的Intent意图

Intent意图,是个非常基础的东西,因为贯穿应用始终,例如跳转Activity、打开Service、向Activity跳转并传递数据、回传数据等等......

首先要知道这个Intent,是一个系统类,所以你使用时,第一件事必然是new对象

Intent intent=new Intent(Lindd.this,Zhuzhendonghua.class);
//跳转Activity  Lindd到Zhuzhendonghua

上面的代码就是从Lindd这个Activity跳转到Zhuzhendonghua这个Actiyity

所以当想要跳转Activity的时候,第一个参数是上下文(粗暴的理解就是现在在哪),第二个参数就是去哪里

再执行以下代码即可跳转

startActivity(intent);//跳转

再比如,在Service服务中对服务进行启动:

Intent intent=new Intent(MainActivity.this, MyService.class);
startService(intent);

接下来就是其中较为复杂的跳转Activity并携带数据

这里,在课堂中教过使用Bundel

                Intent intent=new Intent(Lindd.this,ZIdingyikongjian.class);
                Bundle bundle=new Bundle();
                bundle.putString("account","lindd");
                bundle.putString("password","123123");
                intent.putExtras(bundle);
                startActivity(intent);

但是对于基础差的学生我建议老老实实的多put几个,如下:

                Intent intent=new Intent(Lindd.this,ZIdingyikongjian.class);
                intent.putExtra("account","lindd");
                intent.putExtra("password","123123");
                startActivity(intent);

对于法一,在跳转的Activity中如何获取?如下代码

               Bundle bundle= getIntent().getExtras();
               String account=bundle.getString("account");
               String password=bundle.getString("password");

对于法二,在跳转的Activity中如何获取?如下代码

                getIntent().getStringExtra("account");
                getIntent().getStringExtra("password");

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林林要一直努力

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值