当一个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
主要是以下方法:
第一种:
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
转载于:https://blog.51cto.com/7861921/1544290