Android中Activity之间的数据传递(Intent和Bundle)

       当一个Activity启动另一个Activity时,常常会有一些数据传过去,对于Activity之间的数据交换更简单,因为两个Activity之间进行数据传递交换更简单,因为两个Activity之间本来就有一个“信使”Intent。

      Intent的用途其实有很多,今天用到的只是最基本的。

      视频教程:http://v.youku.com/v_show/id_XNzQxMDUxNTU2.html

                       http://www.iqiyi.com/w_19rsgrq0wt.html#vfrm=14-7-2-1

             邮箱:whsgzcy@foxmail.com


主要是以下方法:

第一种:

          intent = new Intent(MainActivity.this,Second.class);
          bundle = new Bundle();
          bundle.putString("nihao", ed_content.getText().toString());
          intent.putExtras(bundle);
          startActivity(intent);

    接收:

          Intent intent = getIntent();
          Bundle bundle = intent.getExtras();
          tv_show.setText(bundle.getString("nihao"));

 

第二种:

          intent = new Intent();
          intent.setClass(MainActivity.this,Second.class);
          intent.putExtra("key", "dash");
          startActivity(intent); 

    接收:

          Intent intent = getIntent();
          Bundle bundle = intent.getExtras();
          String name = bundle.getString("key");
          tv_show.setText(name);

 

首先对于在API中查到的参数需要注意以下:

context : 这个参数代表了,整个android应用的接口,几乎所有创造的组件都要用到。一般都是 类名.this


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值