android之intent学习
2013-04-17 11:31
274 查看
Intent传值
EditText et = (EditText)findViewById(R.id.etName);//定义的文本框。
String aa = et.getText().toString();//获取文本框内容。
Intent intent = new Intent();
intent.setClass(helloworld.this,android2.class);//helloworld.class为Activity,android2.class为Activity。
intent.putExtra("name", "传值测试!");//设置传递内容。
startActivity(intent);//跳转。
finish();//关闭当前Activity。
第一种写法,用于批量添加数据到Intent:
Intent intent = new Intent();
Bundle bundle = new Bundle();//该类用作携带数据
bundle.putString("name", "学习android");
intent.putExtras(bundle);//为意图追加额外的数据,意图原来已经具有的数据不会丢失,但key同名的数据会被替换
第二种写法:这种写法的作用等价于上面的写法,只不过这种写法是把数据一个个地添加进Intent,这种写法使用起来比较方便,而且只需要编写少量的代码。
Intent intent = new Intent();
intent.putExtra("name", "学习android");
在android2的onCreate方法中取值
【取值方法:String test= (String)(this.getIntent().getExtras().getString("name").toString());】
EditText et = (EditText)findViewById(R.id.etName);//定义的文本框。
String aa = et.getText().toString();//获取文本框内容。
Intent intent = new Intent();
intent.setClass(helloworld.this,android2.class);//helloworld.class为Activity,android2.class为Activity。
intent.putExtra("name", "传值测试!");//设置传递内容。
startActivity(intent);//跳转。
finish();//关闭当前Activity。
第一种写法,用于批量添加数据到Intent:
Intent intent = new Intent();
Bundle bundle = new Bundle();//该类用作携带数据
bundle.putString("name", "学习android");
intent.putExtras(bundle);//为意图追加额外的数据,意图原来已经具有的数据不会丢失,但key同名的数据会被替换
第二种写法:这种写法的作用等价于上面的写法,只不过这种写法是把数据一个个地添加进Intent,这种写法使用起来比较方便,而且只需要编写少量的代码。
Intent intent = new Intent();
intent.putExtra("name", "学习android");
在android2的onCreate方法中取值
【取值方法:String test= (String)(this.getIntent().getExtras().getString("name").toString());】
相关文章推荐
- Android学习之基于显式的Intent的通讯
- Android Activity和Intent机制学习笔记
- Android开发学习笔记:Intent的简介以及属性的详解
- android学习日记20--连接组件之Intent和IntentFilter
- Android学习备忘011——使用Intent传递数据之返回结果
- android学习之intent跳转二简单消息回传
- Android Activity和Intent机制学习笔记
- Android开发学习笔记-3 Activity-2 Activity和Intent关系
- Android学习第二天:Intent传输数据、常用控件和Activity生命周期
- android学习中关于Textview,Button,EditText,连接的设置,Intent,Activity不同状态等的一系列基础知识点
- Android学习总结04之Intent
- android学习之intent学习笔记
- Android开发学习——显式intent和隐式intent(1)
- Android开发学习之路--Activity之Intent
- Android Activity和Intent机制学习笔记
- Android学习——Intent
- Android学习:Activity和Intent
- Android Activity和Intent机制学习笔记
- android基础学习5————隐式意图intent开启系统照相机
- 【Android学习札记】Intent详解