Activity中使用Intent实现页面跳转与参数的传递(转)
新建一个FirstAvtivity.java
package com.zhuguangwei; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class FirstActivity extends Activity {
private Button myButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); myButton = (Button) findViewById(R.id.myButton);
myButton.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
//Intent传递参数
intent.putExtra("testIntent", "123");
intent.setClass(FirstActivity.this, SecondActivity.class);
FirstActivity.this.startActivity(intent);
}
});
}
}
新建第二个SecondActivity.java
package com.zhuguangwei; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView; public class SecondActivity extends Activity{
private TextView myTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
//使用Intent对象得到FirstActivity传递来的参数
Intent intent = getIntent();
String value = intent.getStringExtra("testIntent"); myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText(value);
}
}
两个Activity都要在AndroidMenifest.xml中注册
(转自:http://www.cnblogs.com/top5/archive/2013/01/30/2882967.html)
Activity中使用Intent实现页面跳转与参数的传递(转)的更多相关文章
- JS 页面跳转,参数的传递
当我们通过location.replace()进行页面的跳转时,我们想进行参数的传递,当时学习的时候,以前在网上找过获取方法,已经忘记出处在哪里了.获取方法大概是这样的: 1.将参数通过拼接的方式拼接 ...
- Intent实现页面跳转
Intent实现页面跳转: 1. startActivity(intent) 2. startActivityForResult(intent,requestCode); onActivityResu ...
- Intent实现页面跳转和传值
*Intent称为意图,是Android各大组件连接的桥梁 1.Activity页面跳转 同一个包内 Intent intent = new Intent(); intent.setClass(Mai ...
- [转]Activity详解 Intent显式跳转和隐式跳转
Activity 生命周期 显式 Intent 调用 1 //创建一个显式的 Intent 对象(方法一:在构造函数中指定) 2 Inte ...
- Android成长日记-使用Intent实现页面跳转
Intent:可以理解为信使(意图),由Intent来协助完成Android各个组件之间的通讯 Intent实现页面之间的跳转 1->startActivity(intent) 2->st ...
- html网页中 点击按钮页面跳转
在html页面中 实现点击按钮页面跳转.语句如下: <input type="button" value="跳转" onClick="windo ...
- sharePoint中简单的父页面跳转子页面代码!
1,SharePoint中挺简单的一个父页面跳转到子页面的Js代码!常常用到,每次都到以前的项目中去找代码,挺麻烦! (1)父页面代码. function imgAddParentclick() { ...
- SpringMVC 05: SpringMVC中携带数据的页面跳转
SpringMVC默认的参数对象 SpringMVC默认的参数对象是指,不用再另行创建,相当于SpringMVC内置对象,可以直接声明并使用 默认的参数对象有:HttpServletRequest,H ...
- Android Intent实现页面跳转
Intent可以来协助完成Android各个组件之间的通信 1:startActivity(intent); //直接启动 /* ...
随机推荐
- 【Qt】2.3 使用Qt设计师来创建对话框
安装完Qt OpenSource之后,在开始菜单目录下会有这几个东西. 其中[Designer]是用来设计窗口界面的程序.所以现在可以使用它来设计一个对话框.在[Qt Creator]中,[设计]这一 ...
- 树链剖分求LCA
树链剖分中各种数组的作用: siz[]数组,用来保存以x为根的子树节点个数 top[]数组,用来保存当前节点的所在链的顶端节点 son[]数组,用来保存重儿子 dep[]数组,用来保存当前节点的深度 ...
- Linux下安装mongodb详细过程
本次安装mongodb使用yum.repo方式.详细过程请参考,也列出一些安装过程中的错误,欢迎指正. mongodb版本:3.0 先在linux下cd 到 /etc/yum.repos.d/ 新建脚 ...
- CentOS minimal网络设置
CentOS minimal版本默认不启动网络,所以要自己配置. 配置过程: 编辑配置文件: vi /etc/sysconfig/network-script/ifcfg-eth0 需要更改两项 NM ...
- [翻译] Autofac 入门文档
原文链接:http://docs.autofac.org/en/latest/getting-started/index.html 在程序中使用Autofac的基本模式是: 用控制反转(IoC)的思想 ...
- 手机网游开发指南 - 需要多NB的技术
Agent`K 似乎在三天打鱼N天晒网.只能呵呵了,懒散的家伙. 移动互联网越来越火,其中的网络游戏更是火,熊熊大火. 作为攻城师的你,作为小投资者的你,作为满脑子创意想要实现的你,肯定在四处打听:手 ...
- 关于HTML面试题汇总
一.doctype的作用,严格与混杂模式的区别,有何意义 1.语法格式:<!DOCTYPE html> 2.<!DOCTYPE>不是Html标签,而是告知浏览器此页面使用哪个H ...
- Trianglify - 生成五彩缤纷的 SVG 背景图案
Trianglify 是一个能够生成五颜六色的三角形图案的 JavaScript 库,可以用来作为 SVG 图像和 CSS 背景.它的灵感来自于 Btmills 的 Geopattern,并使用 d3 ...
- MySql基本概念(一)
MySQL基本概念 一. 数据库系统概述: mysql是数据库系统的一种,下面是所有数据库系统中主要的组件. 数据库系统由硬件部分和软件部分构成,硬件主要用于存储数据库中的数据,包括计算机.存储设备. ...
- SharePoint2010升级到SharePoint2013操作手册
SharePoint2010升级到SharePoint2013操作手册 目 录 第一章 前言 3 第二章 升级前准备 3 第三章 升级流程图 5 第四章 升级过程 5 4.1 ...