【开篇骂几句: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()方法参数详解的更多相关文章

  1. php课程---Windows.open()方法参数详解

    Window.open()方法参数详解 1, 最基本的弹出窗口代码   window.open('page.html'); 2, 经过设置后的弹出窗口   window.open('page.html ...

  2. Window.open()方法参数详解

    Window.open()方法参数详解 1, 最基本的弹出窗口代码   window.open('page.html'); 2, 经过设置后的弹出窗口   window.open('page.html ...

  3. ajax方法参数详解与$.each()和jquery里面each方法的区别

    JQuery中$.ajax()方法参数详解 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为g ...

  4. JQuery中$.ajax()方法参数详解

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  5. JQuery中$.ajax()方法参数详解 及 async属性说明

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  6. JQuery中$.ajax()方法参数详解(转载)

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  7. $.ajax()方法参数详解

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  8. 转:JQuery中$.ajax()方法参数详解

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  9. (转)JQuery中$.ajax()方法参数详解

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

随机推荐

  1. CBC之php java兼容版本

    网上搜了N多代码,都是你抄我的,我抄你的,着实让人无语对苍天.经过多番资料的查找,php与java的cbc加密.解密结果终于一致了,代码如下: Java加密解密类: package main; imp ...

  2. JAVA String 工具类

    java StringUtil 字符串工具类 import java.util.ArrayList; import java.util.LinkedHashSet; import java.util. ...

  3. L3-001. 凑零钱

    L3-001. 凑零钱 题目链接:https://www.patest.cn/contests/gplt/L3-001 动态规划 这道题一看就知道应该用背包思想来做,不过想了好久没什么思路(dp实在是 ...

  4. 【转】HTML-based script和URL-based script两种脚本录制方式

    在Web(HTTP/HTML)录制中,有2种重要的录制模式.用户该选择那种录制模式呢?HTML-mode录制是缺省也是推荐的录制模式.它录制当前网页中的HTML动作.在录制会话过程中不会录制所有的资源 ...

  5. 第七十六节,css颜色和透明度,盒子阴影和轮廓,光标样式

    css颜色和透明度,盒子阴影和轮廓,光标样式 学习要点: 1.颜色和透明度 2.盒子阴影和轮廓 3.光标样式 一.颜色和透明度 颜色我们之前其实已经用的很多了,比如字体颜色.背景颜色.边框颜色.但除了 ...

  6. iOS开发The Operation couldn't be completed.(LaunchServicesError error 0.)的解决方法

    显示错误:The Operation couldn't be completed.(LaunchServicesError error 0.)解决办法:第1种方法.点击当前的模拟器,点击IOS Sim ...

  7. 二维小波包分解wpdec2

    load woman; %小波包2尺度(层)分解 t=wpdec2(X,2,'haar'); plot(t);%绘制小波包树 %提取(1,2)处结点.也可以点击上图结点,观察 c12=wpcoef(t ...

  8. Linux中kettle自动化部署脚本

    自己写的一个自动化在Linux中部署kettle的脚本,包括一些遇到的问题在脚本中都有涉及. kettle是官网最新版本pdi-ce-6.1.0.1-196.zip 目前最新版本下载地址:https: ...

  9. linux下svn用法

    linux下svn的一些常用命令: checkout代码到当前目录: svn co svn://192.168.22.23/project  ./ swich 切换分支: 先查看当前工作副本:svn ...

  10. LeetCode OJ 75. Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...