温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-23 20:39:50 来源:网络 阅读:471 作者:郑传余 栏目:移动开发

当一个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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI