两种方式:

一,直接通过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. mac 10.13 build 一个 redis desktop manager

    build 的东西比较多,性能差的电脑编译会很久. 下载地址:https://redisdesktop.com/download 本来想下载一个,但是发现只有 windows 是免费的,不过官网提供了 ...

  2. web中的懒加载

    在Web应用程序中,系统的瓶颈常在于系统的响应速度.如果系统响应速度过慢,用户就会出现埋怨情绪,系统的价值也因此会大打折扣.因此,提高系统响应速度,是非常重要的. Web应用程序做的最多就是和后台数据 ...

  3. 1003 Emergency(25 分)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  4. Discuz!论坛基本搭建

    Crossday Discuz! Board(简称 Discuz!)是北京康盛新创科技有限责任公司推出的一套通用的社区论坛软件系统 一.LAMP环境搭建 参考地址:http://www.cnblogs ...

  5. docker日志引擎说明

    docker原生支持众多的日志引擎,适用于各种不同的应用场景,本篇文档对其作一个简单的说明. Docker日志引擎说明 docker支持的日志引擎如下: none:关闭docker的回显日志, doc ...

  6. Hadoop生态圈-phoenix的视图(view)管理

    Hadoop生态圈-phoenix的视图(view)管理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.

  7. python---CMDB配置管理数据库

    前戏:项目目的 是一个运维自动化管理项目: 为了减少人工干预,降低人员成本 ---资产管理 --操作管理 避免人员直接操作服务器,使用后台去统一操作 一:实现方式 (一)Agent基于shell命令实 ...

  8. poj 2728 Desert King (最优比率生成树)

    Desert King http://poj.org/problem?id=2728 Time Limit: 3000MS   Memory Limit: 65536K       Descripti ...

  9. Android端抓取日志

    一.背景: ADT-Bundlee for Windows 是由GoogleAndroid官方提供的集成式IDE,已经包含了Eclipse,你无需再去下载Eclipse,并且里面已集成了插件,它解决大 ...

  10. Postgresql获取所有schema

    Postgresql 连接方式_连接五要素_psql: https://blog.csdn.net/u011402596/article/details/38510547 postgresql的sho ...