intent.putExtra()方法参数详解
【开篇骂几句:fuck】
1.扯淡intent.putExtra()怎么使用?
2.胡说intent.putExtra();
【扯淡:其实你在问它怎么用的时候,你要明白,你知道不知道这是个什么东东,有必要问吗?有?我猜你已经知道它的基本概念了,它是用来传参数的对不对,是的,就这么简单。但你仍然在网上百度它怎么用,我不理解你为啥要这么做,哦,我又猜到了,我猜啊,你是不知道他的具体参数是怎么个用吧,对了,问题的核心来了,所有安卓开发中的问题都是方法参数的问题】
【putExtra("A",B)中,AB为键值对,第一个参数为键名,第二个参数为键对应的值。顺便提一下,如果想取出Intent对象中的这些值,需要在你的另一个Activity中用getXXXXXExtra方法,注意需要使用对应类型的方法,参数为键名】
要不我举个例子吧,,大家注意注释的地方哈,源码在下面。
来建第一个Activity:MyIntent
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
public class MyIntent extends Activity { /*声明控件对象*/ private EditText et1, et2; private Button bt; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /*取得控件对象*/ et1 = (EditText) findViewById(R.id.et1); et2 = (EditText) findViewById(R.id.et2); bt = (Button) findViewById(R.id.bt); /*为按钮绑定监听器*/ bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { /*取得输入框中的内容*/ String et1Str = et1.getText().toString(); String et2Str = et2.getText().toString(); //创建Intent对象,参数分别为上下文,要跳转的Activity类 Intent intent = new Intent(MyIntent.this, SecondActivity.class); //将要传递的值附加到Intent对象 intent.putExtra("et1", et1Str); intent.putExtra("et2", et2Str); //启动该Intent对象,实现跳转 startActivity(intent); } }); }} |
再建第二个Activity:SecondActivity
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
public class SecondActivity extends Activity{ //声明TextView对象 private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); //取得TextView对象 tv = (TextView) findViewById(R.id.tv); //取得启动该Activity的Intent对象 Intent intent =getIntent(); /*取出Intent中附加的数据*/ String first = intent.getStringExtra("et1"); String second = intent.getStringExtra("et2"); //计算得到结果 int result = Integer.parseInt(first) + Integer.parseInt(second); //设置TextView显示的文本 tv.setText("计算结果为:"+String.valueOf(result)); } } |
intent.putExtra()方法参数详解的更多相关文章
- php课程---Windows.open()方法参数详解
Window.open()方法参数详解 1, 最基本的弹出窗口代码 window.open('page.html'); 2, 经过设置后的弹出窗口 window.open('page.html ...
- Window.open()方法参数详解
Window.open()方法参数详解 1, 最基本的弹出窗口代码 window.open('page.html'); 2, 经过设置后的弹出窗口 window.open('page.html ...
- ajax方法参数详解与$.each()和jquery里面each方法的区别
JQuery中$.ajax()方法参数详解 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为g ...
- JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- JQuery中$.ajax()方法参数详解 及 async属性说明
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- JQuery中$.ajax()方法参数详解(转载)
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- $.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- 转:JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- (转)JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
随机推荐
- 常用类型转换 一.常用int和string类型转换
常用类型转换 一.常用int类型转换1. int.parse(string) 这个类型只支持string类型 2.double doubleType = Int32.MaxValue + 1; i ...
- UVa 1600 Patrol Robot (习题 6-5)
传送门: https://uva.onlinejudge.org/external/16/1600.pdf 多状态广搜 网上题解: 给vis数组再加一维状态,表示当前还剩下的能够穿越的墙的次数,每次碰 ...
- PAT 团体程序设计天梯赛-练习集 L1-005. 考试座位号
每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座 ...
- Amazon EC2 的名词解释
Amazon EC2 Amazon Elastic Compute Cloud (Amazon EC2) Amazon EC2 提供以下功能: 实例:虚拟计算环境 实例预配置模板/Amazon 系 ...
- 大规模Schedule任务实现方案
package com.itlong.bjxizhan.support.web.job.base; import com.itlong.bjxizhan.common.DbContext; impor ...
- 经典dp 最长公共子序列
首先,说明一下子序列的定义…… 一个序列A={a1,a2,a3,...,an},从中删除任意若干项,剩余的序列叫A的一个子序列. 很明显(并不明显……),子序列……并不需要元素是连续的……(一开始的时 ...
- wuzhi 五指 基本知识
参数:m 模块 在于 /coreframe/app/模块文件夹 |默认 content f php文件 控制器 在于/coreframe/app/模块 /文件.php | 默认 index v ...
- 屏幕录像专家2014 v0318 免费版
软件名称: 屏幕录像专家2014软件语言: 简体中文授权方式: 免费试用运行环境: Win8 / Win7 / Vista / WinXP软件大小: 7.9MB图片预览: 软件简介:屏幕录像专家201 ...
- 自定义函数动态执行SQL语句
Oracle 动态SQL有两种写法:用 DBMS_SQL 或 execute immediate,建议使用后者. DDL 和 DML Sql代码 收藏代码 /*** DDL ***/ begin EX ...
- beginBackgroundTaskWithExpirationHandle
[[UIApllication sharedApplication] beginBackgroundTaskWithExpirationHandle:^{}];这个方法在app进入后台时,可以做一些事 ...