本例中MainActivity为:FirstActivity.java

FirstActivity如下:

package com.wyl.intentmultiactivitytest;

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;
import android.widget.EditText; public class FirstActivity extends Activity {
//
Button btn01;
Button btn02;
EditText et; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firstctivity);// 绑定页面
btn01 = (Button) findViewById(R.id.button1);
btn02 = (Button) findViewById(R.id.button2);
et = (EditText)findViewById(R.id.editText1);
btn01.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
// 1.上下文对象,Context
// 2.目标文件
Intent intent = new Intent(FirstActivity.this,
SecondActivity.class);
System.out.println("======kaishi :====");
startActivity(intent);// 实现跳转到第二个页面 }
});
btn02.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
// 1.上下文对象,Context
// 2.目标文件
Intent intent = new Intent(FirstActivity.this,
SecondActivity.class);
System.out.println("======第一个页面的第二种跳转kaishi :====");
startActivityForResult(intent, 1);;// 实现跳转到第二个页面 }
});
} @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==1&&resultCode==2){
String plnr1 = data.getStringExtra("plnr");
String plnr2 = data.getExtras().getString("plnr");
System.out.println("==========:"+plnr1+",plnr2:"+plnr2);
et.setText("data.getStringExtra('plnr1')"+plnr1+",plnr2 = data.getExtras().getString('plnr')的方式"+plnr2);
}
}
}

  SecondActivity:

package com.wyl.intentmultiactivitytest;

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;
import android.widget.EditText;
import android.widget.Toast; public class SecondActivity extends Activity {
Button btn01;
Button btn02;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);// 绑定页面
System.out.println("=====wo shi the second yemian =====");
btn01 = (Button) findViewById(R.id.button21);
btn02 = (Button) findViewById(R.id.button22);
et = (EditText)findViewById(R.id.editText01);
btn01.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(SecondActivity.this, FirstActivity.class);
System.out.println("==cong dier tiaodao diyiye==");
startActivity(intent);
}
});
btn02.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
String content = et.getText().toString();//获取评论的内容
intent.putExtra("plnr", content); //2是状态码,随便自己设置,用来判断是哪个页面的返回值,自己不弄混了就行
setResult(2, intent); //这是最关键的一步,
Toast.makeText(SecondActivity.this, intent.getExtras().getString("plnr"),1000);
finish();//关闭该页面,就会自动返回到了第一页了。
}
}); }
}

  相关的layout文件:

firstctivity.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="new Intent(context,目标activity.class),startActivity(intent)方式跳转" /> <Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="第二种方式跳转" /> <EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="我只是个提示框框而已"> <requestFocus />
</EditText> </LinearLayout>

  second_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <EditText
android:id="@+id/editText01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="录入要返回到第一页的内容" />
<Button
android:id="@+id/button21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我是第二个activity页面" />
<Button
android:id="@+id/button22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="startActivityForResult方式返回,并且回传数据" />
</LinearLayout>

  效果图如下:

Activity跳转的更多相关文章

  1. 用Dart&Henson玩转Activity跳转

    用Dart&Henson玩转Activity跳转 Extra是Android标准的组件之间(Activity/Fragment/Service等)传递数据的方式.本文介绍了开源项目Dart的使 ...

  2. Android之Activity跳转

    简述 如果把每个activity看成一个页面的话,那么activity之间的跳转和页面的之间的跳转基本上是一样的.首先需要监听一个事件,当这个事件发生的时候,就进行跳转.html中有个<a sr ...

  3. android activity 跳转传值问题研究

    intent = new Intent(); intent.setClass(LoginActivity.this, RegActivity.class); startActivity(intent) ...

  4. 【原创】Android 从一个Activity跳转到另外一个Activity

    Android四大组件activity使用,实现两个activity之间的跳转 基本流程:创建两个activity-将其中一个activity中组件作为事件源-通过组件事件的处理借助intent对象实 ...

  5. tabhost中activity跳转动画不显示的解决办法

    [1]如果是tabhost中的activity跳到其他的activity,用这篇blog的方法即可 http://blog.sina.com.cn/s/blog_8db8914301010t31.ht ...

  6. android 15 activity跳转

    从一个屏幕跳到另一个屏幕,一个activity跳转到另一个activity,Intent类用于组件之间传递数据和跳转,组件包括不仅activity. package com.sxt.day04_01; ...

  7. Android Activity跳转动画,让你的APP瞬间绚丽起来

    我们都知道绚丽的APP总会给用户耳目一新的感觉,为了抓住用户更大网络公司使出浑身解数让自己的产品更绚丽,而绚丽最简单的效果就是Activity跳转效果,不仅可以让用户看起来舒服,而且实现起来也特别简单 ...

  8. Activity跳转时传递Bitmap对象的实现

    前言 相信大家可能都了解Activity跳转时我们是能够传递參数的,比方使用Intent传递或者Bundle来传递,把当前Activity的一些信息传递给将要跳转到的新的Activity.可是不知道大 ...

  9. Android的Activity跳转动画各种效果整理

    Android的Activity跳转就是很生硬的切换界面.其实Android的Activity跳转可以设置各种动画,本文整理了一些,还有很多动画效果,就要靠我们发挥自己的想象力 大家使用Android ...

  10. android入门,activity跳转,并传递message

    首先是布局文件,如下: activity_main.xml <?xml version="1.0" encoding="utf-8"?> <L ...

随机推荐

  1. .net DataTable 取值辅助类

    DataTableCommon类主要是帮助取值 方法列表: public static string GetCellString(DataTable dt,int row, int column) p ...

  2. Linux第三方源

    由于版权等各方面原因,很多时候在基础安装完Linux后,满多软件并不包含在yum(对于Ubuntu可能是apt-get)源中. 因此可以去下载第三方源,安装下载第三方软件.当然,如果习惯了源代码编译安 ...

  3. 射频识别技术漫谈(27)——CPU卡概述

    智能卡按安全级别可以分为三类:存储器卡.逻辑加密卡和CPU卡,其中CPU卡是安全级别最高的.从“CPU”这个名字可以看出,CPU卡最大的特点就是卡片里面有一个"CPU",有了CPU ...

  4. ISO/IEC14443和15693的对比有何具体区别

    ISO14443 ISO14443A/B:超短距离智慧卡标准.这标准订出读取距离7-15厘米的短距离非接触智慧卡的功能及运作标准,使用的频率为13.56MHz.     ISO14443定义了TYPE ...

  5. Liunx 环境下vsftpd的三种实现方法(超详细参数)

    以下文章介绍Liunx 环境下vsftpd的三种实现方法 ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.0.3.tar.gz,目前已经到2.0.3版本.假 ...

  6. php 实现简单的登录

    //登录页面: V层前端模板: Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp/Home/Tpl/Login $ ls inde ...

  7. HDU 1997 汉诺塔VII

    题解参考博客: http://blog.csdn.net/hjd_love_zzt/article/details/9897281 #include <cstdio> ],yes; int ...

  8. hdoj 3065 病毒侵袭持续中(AC自动机)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 思路分析:问题需要模式匹配多个模式串,需要注意的是模式串会包含和重叠,需要对AC自动机的匹配过 ...

  9. Suricata, to 10Gbps and beyond(X86架构)

    Introduction Since the beginning of July 2012, OISF team is able to access to a server where one int ...

  10. rman备份优化思路

    本章不讲rman备份原理.仅仅提供一些思路 1.oracle11g 选择压缩算法为中级: 2.添加rman备份的通道. 以上两种做法.添加CPU的利用率,降低IO 3.指定rate參数 这个rate和 ...