两种方式:

一,直接通过Bundle对象来传递:

  如果我们想要给“收件人”Activity说点什么的话,那么可以通过下面这封“E-mail”来将我们的消息传递出去

  Intent intent=new Intent(CurrentActivity.this,OtherActivity.class);

  //创建一个带“收件人地址“的email

  Budle budle = new Budle();

  //创建email内容

  bundle.putBoolean("boolean_key",true);//编写内容

  bundle.putString("string_key","string_value");

  intent.putExtra("key",budle);//封装email

  startActivity(intent);//启动新的Activity

二,使用Intent定义的Bundle对象

  上面我们通过bundle对象来传递信息,bundle维护了一个HashMap<String,Object>对象,将我们的数据存贮在这个HashMap中来进行传递,

但是像上面这样的代码稍显复杂,因为Intent内部为我们准备好了一个bundle,所以我们也可以使用这种更为简便的方法:

  Intent intent = new Intent(EX06.this, OtherActivity.class);

  intent.putExtra("boolean_key",true);

  intent.putExtra("String_key","string_value");

  startActivity(intent);

接受:

  Intent intent = getIntent();

  intent.getBooleanExtra("boolean_key",false);

  intent.getStringExtra("string_key");

例如

//Item单击事件,单击后跳转到新的Activyty,并显示完整的内容
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {

//获取当前Item的完整数据
Blog bg = blogList.get(position);
String tile = bg.getBlogTile();
String contents =bg.getBlogText();

//开始一个新的intent
Intent intent = new Intent(PULLParserActivity.this, BlogActivity.class);
intent.putExtra(KEY_TILE, tile);
intent.putExtra(KEY_CONTENTS, contents);
startActivity(intent);
}

新的Activity里

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_blog);

//接受intent数据

Intent intent = getIntent();

String tile = intent.getStringExtra(KEY_TILE);
String contents = intent.getStringExtra(KEY_CONTENTS);

tvTile = (TextView) findViewById(R.id.textView_tile2);
tvContents = (TextView) findViewById(R.id.textView_contents2);

tvTile.setText(tile);
tvContents.setText(contents);

}

[android]Intent跳转新的Activity可以传递数据过去的更多相关文章

  1. android中使用Intent在activity之间传递数据

    android中intent传递数据的简单使用: 1.使用intent传递数据: 首先将需要传递的数据放入到intent中 Intent intent = new Intent(MainActivit ...

  2. 【Android 复习】 : Activity之间传递数据的几种方式

    在Android开发中,我们通常需要在不同的Activity之间传递数据,下面我们就来总结一下在Activity之间数据传递的几种方式. 1. 使用Intent来传递数据 Intent表示意图,很多时 ...

  3. Android 笔记-Fragment 与 Activity之间传递数据

    Fragment 与 Activity之间传递数据有两种方法.一种是使用setArgument,一种是使用接口回调.以下先学习第一种方法. (1)使用setArgument方法: 为了便于理解,我在这 ...

  4. Activity之间传递数据的方式及常见问题总结

    Activity之间传递数据一般通过以下几种方式实现: 1. 通过intent传递数据 2. 通过Application 3. 使用单例 4. 静态成员变量.(可以考虑 WeakReferences) ...

  5. Activity之间传递数据或数据包Bundle,传递对象,对象序列化,对象实现Parcelable接口

    package com.gaojinhua.android.activitymsg; import android.content.Intent; import android.os.Bundle; ...

  6. 28、activity之间传递数据&批量传递数据

    import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android ...

  7. 在activity之间传递数据

    在activity之间传递数据 一.简介 二.通过intent传递数据 1.在需要传数据的界面调用 intent.putExtra("data1", "我是fry&quo ...

  8. 使用Bundle在Activity间传递数据

    使用Bundle在Activity间传递数据 源Activity public class SourceActivty extends Activity { private Intent intent ...

  9. Android Intent (可通过URL启动 Activity)

    Intent分为两大类: (1)显性的(Explicit) (2)隐性的(Implicit) 对于隐性意图,在某些时候, 应用程序只是想启动具有某种特征的组件, 并不想和某个特定的组件耦合. 使用In ...

随机推荐

  1. matlab和C语言实现最小二乘法

    参考:https://blog.csdn.net/zengxiantao1994/article/details/70210662 Matlab代码: N = ; x = [ ]; y = [ ]; ...

  2. Vue入坑教程(二)——项目结构详情介绍

    之前已经介绍了关于Vue的脚手架vue-cli的安装,以及一些文件目录介绍.具体可以查看<vue 入坑教程(一)--搭建vue-cli脚手架> 下面简单说一下具体的文件介绍 (一) pac ...

  3. poj 1284 Primitive Roots (原根)

    Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS   Memory Limit: 10000K       Descr ...

  4. noi题库(noi.openjudge.cn) 1.11编程基础之二分查找T01、02、04

    T01 查找最接近的元素 描述 在一个非降序列中,查找与给定值最接近的元素. 输入 第一行包含一个整数n,为非降序列长度.1 <= n <= 100000.第二行包含n个整数,为非降序列各 ...

  5. 张鑫旭:Promise异步编程模式

    参考文章: http://www.zhangxinxu.com/wordpress/2014/02/es6-javascript-promise-%E6%84%9F%E6%80%A7%E8%AE%A4 ...

  6. 【学习笔记】FreeMarker 之于Servlet与Stuts2的应用

    FreeMarker应用在Servlet(0配置web.xml形式): 准备环境: tomcat7.eclipse最新版.jdk1.8.freemarker v2.3.20.jar 举例项目结构图: ...

  7. Web Api问题汇总

    在公网上布署Web Api的时候,不能调用,返回404 在web.config中 Adding the following to the web.config file worked for me: ...

  8. 你都掌握了吗?jQuery 选择器大全

    在 Dom 编程中我们只能使用有限的函数根据 id 或者 TagName 获取 Dom 对象. 然而在 jQuery 中则完全不同,jQuery 提供了异常强大的选择器用来帮助我们获取页面上的对象, ...

  9. Java 图片转字节流 实现 图片->字节流(字符串)->图片

    //该方法实现图片转String 参数为图片的路径 可以是file.toString()得到public String testUpload(String path) { try { String s ...

  10. HDU 2073 叠框

    解题报告:一个字符串的题,最恶心的还是格式问题,PE了很多次,要求是每个测试数据的后面都带有一个空行,但是最后一个不能有空行,所以只能把第一组 数据的前面不输出空行,而后面的每一组数据都输出空行,这样 ...