您的位置:首页 > 移动开发 > Android开发

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

2014-08-25 10:09 483 查看
当一个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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android bundle
相关文章推荐