展会信息港展会大全

Intent传值的方法 android开发教程
来源:互联网   发布日期:2016-01-14 09:19:30   浏览:1382次  

导读:EditText et = (EditText)findViewById(R.id.etName);//定义的文本框。String aa = et.getText().toString();//获取文本框内容。Intent intent = new Intent();intent.setClass(helloworld.this,andro......

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"));】

赞助本站

人工智能实验室

相关热词: Intent 传值

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港