首先看看两种传递方法演示样例:(一个简单姻缘计算器)

主Activity

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void click(View v){
Intent intent = new Intent(this, SecondActivity.class);
//把数据封装至intent对象中
// intent.putExtra("malename", "张三");
// intent.putExtra("femalename", "芙蓉姐姐"); //把数据封装至bundle对象中
Bundle bundle = new Bundle();
bundle.putString("malename", "<span style="font-family: Arial, Helvetica, sans-serif;">张三</span>"<span style="font-family: Arial, Helvetica, sans-serif;">);</span>
bundle.putString("femalename", "芙蓉姐姐"); //把bundle对象封装至intent对象中
intent.putExtras(bundle);
startActivity(intent);
} }
import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView; public class SecondActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second); Intent intent = getIntent();
//从intent对象中把封装好的数据取出来
// String maleName = intent.getStringExtra("malename");
// String feMaleName = intent.getStringExtra("femalename"); Bundle bundle = intent.getExtras();
String maleName = bundle.getString("malename");
String feMaleName = bundle.getString("femalename"); Random rd = new Random();
int yinyuan = rd.nextInt(100); TextView tv = (TextView) findViewById(R.id.tv);
tv.setText(maleName + "和" + feMaleName + "的姻缘值为" + yinyuan);
}
}

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical"
> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是姻缘计算器。非常准的哟" /> <EditText
android:id="@+id/et_malename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="张三"
/>
<EditText
android:id="@+id/et_femalename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="芙蓉姐姐"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="计算"
android:onClick="click"
/>
</LinearLayout>

activity_second.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是第二个Activity" /> </RelativeLayout>

Android--Activity在跳转时携带数据的更多相关文章

  1. Android Activity切换(跳转)时出现黑屏的解决方法

    在两个Activity跳转时,由于第二个Activity在启动时加载了较多数据,就会在启动之前出现一个短暂的黑屏时间,解决这个问题比较简单的处理方法是将第二个Activity的主题设置成透明的,这样在 ...

  2. Android Activity间跳转与传递数据

    1 概述 Activity之间的跳转主要使用 startActivity(Intent intent); startActivityForResult(Intent intent,int reques ...

  3. 微信小程序:页面跳转时传递数据到另一个页面

    一.功能描述 页面跳转时,同时把当前页面的数据传递给跳转的目标页面,并在跳转后的目标页面进行展示 二.功能实现 1. 代码实现 test1页面 // pages/test1/test1.js Page ...

  4. [转]Android:Activity+Fragment及它们之间的数据交换(一)

    2014-05-18         来源:Android:Activity+Fragment及它们之间的数据交换(一)   简介: 为什么要用Fragment?使用Fragment可以在一个Acti ...

  5. Android:Activity+Fragment及它们之间的数据交换.

    Android:Activity+Fragment及它们之间的数据交换 关于Fragment与Fragment.Activity通信的四种方式 比较好一点的Activity+Fragment及它们之间 ...

  6. 自定制页面跳转时携带原搜索参数的URL

    介绍 django自带反向解析生成URL的功能,目的是避免硬编码,较少代码维护的代价. 前端页面使用模板语法,如:{% url "rbac: request menu_list" ...

  7. Android activity界面跳转动画

    实现activity界面跳转动画 1.在startActivity方法之后加入: overridePendingTransition(R.anim.pull_in_right, R.anim.pull ...

  8. Android:Activity+Fragment及它们之间的数据交换(一)

    简单介绍: 为什么要用Fragment?使用Fragment能够在一个Activity中实现不同的界面. Fragment与Fragment之间的动画切换,远比Activity与Activity之间的 ...

  9. Android:Activity的跳转

    // 实际开发中常用的方法 Intent intent = new Intent(); intent.setClass(MainActivity.this, LoginActivity.class); ...

随机推荐

  1. HTTP/2 带来的新颖

    Binary Frames HTTP2 在TCP层之上 HTTP下增加了Binary Frames协议, 基于该协议HTTP Request/Response 可以被分拆成由Frame组成的Strea ...

  2. java解决动态的锁顺序死锁的方案

    直接上代码 public class Test3 { public static Object fromAccount = new String("1"); public stat ...

  3. 第1节 MapReduce入门:11、mapreduce程序的入门

    1.1.理解MapReduce思想 MapReduce思想在生活中处处可见.或多或少都曾接触过这种思想.MapReduce的思想核心是“分而治之”,适用于大量复杂的任务处理场景(大规模数据处理场景). ...

  4. delphi byte to of set

    最佳方案 type // Controls.TCMMouseWheel relies on TShiftState not exceeding 2 bytes in size TShiftState ...

  5. [GXOI/GZOI2019]与或和(单调栈)

    想了想决定把这几题也随便水个解题报告... bzoj  luogu 思路: 首先肯定得拆成二进制30位啊 此后每一位的就是个01矩阵 Q1就是全是1的矩阵个数 Q2就是总矩阵个数减去全是0的矩阵个数 ...

  6. Nginx(alias 和 root的区别)

    Nginx(alias 和 root的区别)1.alias 和 root 的区别: location /request_path/image { root /local_path/image/; } ...

  7. Hadoop-2.7.1伪分布--安装配置hbase 1.1.2

    hbase-1.1.2下载地址:http://www.eu.apache.org/dist/hbase/stable/hbase-1.1.2-bin.tar.gz 下载之后解压至\usr\local目 ...

  8. windows下mysql 5.7版本中修改编码为utf-8的方法

    方法如下 首先通过 show variables like 'character_set_%';查看mysql字符集情 默认编码为 latin1 然后关闭数据库 在mysql安装目录下找到my.ini ...

  9. 语法,if,while循环,for循环

    目录 一.语法 二.while循环 三.for循环 一.语法 if: if判断其实是在模拟人做判断.就是说如果这样干什么,如果那样干什么.对于ATM系统而言,则需要判断你的账号密码的正确性. if 条 ...

  10. 程序包javax.servlet.http不存在

    在maven test项目时,出现错误: java:[7,26] 程序包javax.servlet.http不存在 原因:pom.xml中未引入javax.servlert-api相关的包 <d ...