博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Intent传值
阅读量:6877 次
发布时间:2019-06-26

本文共 869 字,大约阅读时间需要 2 分钟。

hot3.png

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

 

更详细http://jojol-zhou.iteye.com/blog/1401905

转载于:https://my.oschina.net/kevinvane/blog/72669

你可能感兴趣的文章
树莓派使用实例之:2 Pi R 第二篇:Web服务器
查看>>
数据挖掘比赛通用框架
查看>>
《Linux C编程从入门到精通》一1.4 Linux的常用命令
查看>>
《iOS 9 开发指南》——第6章,第6.5节创建一个界面
查看>>
《Adobe Flash CS4 ActionScript 3.0中文版经典教程》——导读
查看>>
5 个不用 Bootstrap 的理由
查看>>
《OpenCL实战》一1.3 类比:OpenCL处理和纸牌游戏
查看>>
《渐进增强——跨平台用户体验设计》一1.8 分层次设计
查看>>
为什么 mysql 里的 ibdata1 文件不断的增长?
查看>>
并发网2014.8月阅读量Top10
查看>>
Java RESTful Web Service实战(第2版) 1.9 本章小结
查看>>
集合和Collections、Map的UML类图
查看>>
《移动App测试的22条军规》——导读
查看>>
《动手搭建智能家居系统》——导读
查看>>
Flink – window operator
查看>>
Copycat - configure
查看>>
Android StringEntity() 和 UrlEncodedFormEntity() 的区别
查看>>
04. WebApp2.0时代启程:跨平台的JSPatch
查看>>
使用iphone作为远程仓库的方案
查看>>
C++语言基础 例程 纯虚函数
查看>>